Solr:通过db-data-config.xml查询索引子文档

时间:2017-10-30 18:20:22

标签: solr nested parent-child

我试图将嵌套文档索引到父文档,但是没有在SOLR中找到索引数据的预期结构。请纠正我在solr配置中出现的问题,如下所述。

表格结构: enter image description here

  1. db-data-config.xml

    <document>
    <entity name="parent" pk="parent_id" query="SELECT parent_id, name, salary, country from parent" deltaQuery="select parent_id, name, salary, country from parent where updated_at &gt ${dataimporter.last_index_time}">
    <field column="parent_id" name="id" />
    <field column="parent_id" name="parent_id" />
    <field column="name" name="name" />
    <field column="salary" name="salary" /> 
    <field column="country" name="country" />
    <entity name="child" child="true" pk="child_id" query="select child.child_id, child.parent_id, child.child_name from child where child.parent_id='${parent.parent_id}' ">
        <field column="parent_id" name="id"  /> 
        <field column="child_id" name="child_id"  />
        <field column="child_name" name="child_name"  />
    </entity>
    </entity>
    </document>
    
  2. 管理型模式:

    <!-- parent table fields -->
    <field name="parent_d" type="text_general" indexed="true" stored="true"/>
    <field name="name" type="text_general" indexed="true" stored="true"/>
    <field name="salary" type="text_general" indexed="true" stored="true"/>
    <field name="country" type="text_general" indexed="true" stored="true"/>
    <!-- child table fields -->
    <field name="child_id" type="text_general" indexed="true" stored="true"/>
    <field name="child_name" type="text_general" indexed="true" stored="true"/>
    
  3. 索引文档的结果不是嵌套的,它似乎是平面表示:

  4. "response":{"numFound":4,"start":0,"docs":[ { "country":"IND", "parent_id":"1", "name":"p1", "salary":"11", "_version_":1582614969479856128 },
    { "id":"1", "child_id":"1", "child_name":"c1", "_version_":1582614969479856128 }, { "country":"USA", "parent_id":"2", "name":"p2", "salary":"222", "_version_":1582614969546964992 },
    { "id":"2", "child_id":"2", "child_name":"c2", "_version_":1582614969546964992 } ] }

    预期:

    "response":{"numFound":4,"start":0,"docs":[      
    {
        "parent_id":"1",
        "country":"IND",
        "name":"p1",
        "salary":"11",
        "child":{
            "parent_id":"1",
            "child_id":"1",
            "child_name":"c1",
        },
        "_version_":1582614969479856128
        },      
        {
        "parent_id":"2",
        "country":"USA",
        "name":"p2",
        "salary":"222",
        "child":{
            "parent_id":"2",
            "child_id":"2",
            "child_name":"c2",
        },
        "_version_":1582614969546964992
        }
    ]
    }
    

1 个答案:

答案 0 :(得分:0)

Solr也将子文档存储为独立文档,因此您看到的是正常的。但是有一些管道,所以你可以让它们与父母一起回来(并查询一层并获得另一层等)。

Yonik仔细阅读this post,了解如何查询以获得孩子等等。