Search code examples
solrdataimporthandlersolr6

indexing multiple non-relational tables in DB


I am using solr6.4.X to index mysql data. I have setup dataimporthandler for the same. The problem is as long as we have relational tables in DB it works fine, but I have ~10 tables which doesn't have any relationships in between them.

I tried adding them as seeperate entities but for some unknown reason it was not working. So basically I need views on 2 points:

  • Storing non-relational tables into Solr via dataimporthandler
  • Retrieving data from individual tables(I am using Solrj to query the data).

any help is much appreciated. Thanks


Solution

  • not sure what was the issue in you DIH setup, but having several entities, one per table, with tables not having relationships among them is perfectly fine. Works without any issue. Your problem should be fixable for sure.

    Without knowing more about your issue, one guess: a typical problem people face in that scenario is they use the pk from each table as Solr doc id, and they overwrite each other on the Solr side. You must append something unique to the table to the solr id so they are unique inside Solr.

    EDIT: yes, the problem is what I guessed, you have this:

    <entity name="encounter_notes" pk="id" query="SELECT * from encounter_notes">
            <field column="id" name="id" />
            <field column="encouter_id" name="encouter_id" />
    

    The id of each entity will overwrite each other, do this for all tables:

    <entity name="encounter_notes" pk="id" query="SELECT CONCAT('notes_',id) as id, ... from encounter_notes">
            <field column="id" name="id" />
            <field column="encouter_id" name="encouter_id" />  
    

    So you have ids like: notes_1, notes_2, financial_class_1...