How to index and search for two different tables that are in the same data source using one-time instances or Solr Templates that do not work properly

I want to index and search for two different objects.

File Name: db-data-config.xml

<dataConfig> <dataSource name="myindex" driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://test-pc:1433;DatabaseName=SampleDB" user="username" password="password" /> <document> <entity name="Employees" query="select * from employee" transformer="TemplateTransformer" dataSource="myindex"> <field column="id" name="singlekey" /> <field column="eId" name="eid" /> <field column="eName" name="ename" /> <field column="entity" template="Employee" name="entity" /> </entity> <entity name="Products" query="select * from products" transformer="TemplateTransformer" dataSource="myindex"> <field column="id" name="singlekey" /> <field column="pId" name="pid" /> <field column="pName" name="pname" /> <field column="entity" template="Product" name="entity" /> </entity> </document> 

File Name: schema.xml

 <?xml version="1.0" encoding="UTF-8" ?> <schema name="db" version="1.1"> <types> <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/> </types> <fields> <!-- Employee --> <field name="eid" type="string" indexed="true" stored="true" required="true" multiValued="false" /> <field name="ename" type="string" indexed="true" stored="true" required="true" multiValued="false" /> <!-- Products --> <field name="pid" type="string" indexed="true" stored="true" required="true" multiValued="false" /> <field name="pname" type="string" indexed="true" stored="true" required="true" multiValued="false" /> <!--Common fields--> <field name="entity" type="string" indexed="true" stored="true" required="true" multiValued="false" /> <field name="singlekey" type="string" indexed="true" stored="true" required="true" multiValued="false" /> </fields> <uniqueKey>singlekey</uniqueKey> </schema> 

By the link below:
stack overflow
This problem can be solved using a static field (adding a new field - here is its "entity" ). But I noticed that after adding a second object, it cannot even index the data.

As the picture below. Multiple entity issue - Template Transformer issue

Its ability to retrieve 10 records from a sql server database, but an index of 0 rows means that the indexing process is not running. Therefore, it is not even possible to perform a search. Can anyone solve this problem? Thanks in advance.

+8
xml indexing solr data-import dataimporthandler
source share
2 answers

All fields in your schema have

 required="true". 

You tell Solr that the results from each object must have ALL of the eid, ename, pid, pname, entity, and singlekey fields.

The employee does not have a pid or pname field, so pid and pname are not required. In the same sense, the product does not have an eid or ename field, so eid and ename are not required.

Delete

 required="true". 

of pid, pname, eid and ename will allow you to index.

+1
source share

You tried to index your entities separately from the admin screen

 http://<hostname>:<portnum>/solr 
-2
source share

All Articles