Data import in solr from multiple entity

2019-09-17 22:45发布

问题:

I am trying the Data Import Handler for SQLServer Database.

I added the DIhandler in solrconfig.xml, created a data-config.xml according to my database schema and also added a field in the schema.xml which was different. I am connecting with SQLServer database.

After I connect and I run the dataimport?command=full-import I am not getting xml tag (data) properly.

in my data-config.xml*****

 <document name="Product"> 
    <entity dataSource="ds-1" name="Item" pk="Item_ID"
            query="select  item.Item_ID, itemcode from item"
            deltaImportQuery="select  item.Item_ID, itemcode from item  where 
                          item.Item_ID='${dataimporter.delta.Item_ID}' "
            deltaQuery="select Item_ID from item where last_modified > 
                    '${dataimporter.last_index_time}' ">

          <entity name="ReturnSolrFilter"
              query="select Item_Id , CustomField_ID as CustomField from 
                         ReturnSolrFilter where Item_Id = '${Item.Item_ID}' "
              deltaQuery="select Item_Id , CustomField_ID as CustomField from 
                              ReturnSolrFilter where last_modified > 
                              '${dataimporter.last_index_time}' "
              parentDeltaQuery="select Item_ID from item where Item_ID = 
                              '${ReturnSolrFilter.Item_ID}' ">
         </entity>

   </entity>
  </document>

Now the Result is *******

  1. if data found in both Table

    < doc>

      < int name="Item_ID">13773< /int>
    
      < str name="itemcode">15438680< /str>
    
        < arr name="CustomField">
    
            < str>31< /str>
    
            < str>32< /str>
    
        < /arr>
    < /doc>
    
  2. if data found in Item Table but not in ReturnSolrFilter then Tag is not generated(This is Actual Problem CustomField tag not generated)

< doc>

< int name="Item_ID">13773< /int>

< str name="itemcode">15438680< /str>

< /doc>

回答1:

I think you will need to wrap your CustomField_ID with isnull: isnull(Custom_ID, '') as CustomField that should force the DataImportHandler to create an empty field for CustomField in the generated XML for submission as the solr document.