SOLR DataImportHandler how to treat a nested entity as a JSON array

I am struggling with SOLR and SQL Data Import. I need to index the data coming from two tables, the first of which is the “masters”, the second is the “details”. The relationship between the two tables is 1-to-n, and it is executed by the colm m_id command, which is present in both tables:

CREATE TABLE "masters" (m_id             NUMBER(10), 
                        m_code           VARCHAR2(100 CHAR), 
                        m_description    VARCHAR2(1000 CHAR),
                        PRIMARY KEY (m_id));

CREATE TABLE "details" (d_id             NUMBER(10), 
                        s_code           VARCHAR2(100 CHAR), 
                        s_description    VARCHAR2(1000 CHAR), 
                        m_id             NUMBER(10), 
                        PRIMARY KEY (d_id),
                        CONSTRAINT fk_details_masters FOREIGN KEY (m_id) REFERENCES "masters"(m_id));

I would like to have one indexed document for each row present in the master table, each document should contain an ARRAY table of details.

The result that I anticipated in my mind looks something like this:

master = {
 "ID": "1"
 "m_code": "master53",
 "m_description": "John Doe",
 "details": [ 
              {
               "d_code": "detail001",
               "d_description": "Shirts"
              },
              {
               "d_code": "detail002",
               "d_description": "Shoes"
              },
              {
               "d_code": "detail003",
               "d_description": "hats"
              }
            ]
}

But I can only create something like this:

master = {
 "ID": "1",
 "m_code": "master53",
 "m_description": "John Doe",
 "d_code": ["detail001","detail002","detail003"],
 "d_description": ["Shirts","Shoes","hats"]
}

using this configuration:

<dataConfig>
  <dataSource type="JdbcDataSource" 
              driver="oracle.jdbc.driver.OracleDriver"
              url="jdbc:oracle:thin:@//dora64svil.icc.crifnet.com:1521/cbrisvil.dbcrif.net"
              user="CBBTC" 
              password="w4.gJ6Qf1p7Z_i4qFp3W_d"/>
  <document>
    <entity name="master" rootEntity="True"
            query="SELECT m_id, m_code, m_description from master">
        <field column="m_id" name="ID"/>
        <field column="m_code" name="m_code_s"/>
        <field column="m_description" name="m_description_s"/>
        <entity name="details"  rootEntity="False"
                query="SELECT d_code, d_description from details where = m_id '${master.m_id}'">
            <field column="d_code" name="d_code_ss"/>
            <field column="d_description" name="d_description_ss"/>
        </entity>
    </entity>
  </document>
</dataConfig>

schema.xml, . ( "_s" "_ss" )

, "" , ? , ?

+4
2

Solr .

fq=_root_:<your_id> .

, , , type_s "master" "details", , TemplateTransformer.

, , :

"groupValue":master,
doc: {
 "ID": "1"
 "m_code": "master53",
 "m_description": "John Doe",
}

"groupValue":"details",
 "docs":  
              {
               "d_code": "detail001",
               "d_description": "Shirts"
              },
              {
               "d_code": "detail002",
               "d_description": "Shoes"
              },
              {
               "d_code": "detail003",
               "d_description": "hats"
              }
0

multiValued = true schema.xml

-1

All Articles