How to index and search two different tables which are in same datasource using single solr instance Or Solr Template fields not working properly
Asked Answered
V

2

8

I want to index and search two different entity.

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>

As per below link:
https://mcmap.net/q/1474658/-how-to-index-and-search-two-different-tables-which-are-in-same-datasource-using-single-solr-instance-two-different-search-fields-no-joins
This problem can solve by using static field (adding new field - here its 'entity'). But I saw that after adding second entity, it can't even index the data.

As per picture shown below.Multiple entity issue - Template Transformer issue

Its able to fetch 10 records from sql server database but index 0 rows, means no indexing process done. So even can't search. Anyone can solve this problem? Thanks in advance.

Viridescent answered 20/3, 2014 at 13:13 Comment(1)
Any workaround for this question???Martguerita
O
1

All of the fields in your schema have

required="true".

You're telling Solr that the results from each entity need to have ALL of the eid, ename, pid, pname, entity, and singlekey fields.

Employee doesn't have a pid or pname field, so pid and pname shouldn't be required. In the same sense, Product doesn't have a eid or ename field, so eid and ename shouldn't be required.

Removing

required="true".

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

Odalisque answered 5/12, 2014 at 21:55 Comment(1)
Thanks, you are true that's the only root cause for not indexing data. (y)Viridescent
B
-2

Have you tried indexing your entities individually from admin screen

http://<hostname>:<portnum>/solr
Brandes answered 27/11, 2014 at 6:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.