簡體   English   中英

Apache Solr-索引數據

[英]Apache Solr - index data

我有兩個表:tableA和tableB。 這些表之間存在一對多的關系。 tableA中的一行對應於tableB中的多行。 我有查詢:

select aa.id, aa.first_name, aa.last_name, bb.address_home, bb.address_coresp from testA aa, testB bb where aa.id = bb.testA_fk;

返回許多行-例如3:

1   John    Terry   HOME 1      CORESP_1
1   John    Terry   HOME 11     CORESP_11
1   John    Terry   HOME 111    CORESP_111

當我將此查詢插入solr的data-config.xml文件和索引數據中時,結果為:

{"address_home": ["HOME 111"],
"address_coresp": ["CORESP_111"],
"id": "1",
"LAST_NAME": "Terry",
"FIRST_NAME": "John",
"_version_": 1513906493806608400
}

地址結果只有一個,而不是三個。

我的data-config.xml的片段:

<document name="testDoc">

<entity name="testA" query="select aa.id, aa.first_name, aa.last_name, bb.address_home, bb.address_coresp from testA aa, testB bb where aa.id = bb.testA_fk">
    <field column="id" name="id" />
    <field column="first_name" name="first_name" />
    <field column="last_name" name="last_name" />
    <field column="address_home" name="address_home" />
    <field column="address_coresp" name="address_coresp" />
</entity>
</document>

在schema.xml中,我將multiValued設置為true:

<field name="address_home" type="text_general" indexed="true" stored="true" multiValued="true" /><field name="address_coresp" type="text_general" indexed="true" stored="true" multiValued="true" />

我知道我的問題的解決方案是嵌套實體元素:

<entity name="testA" query="select * from testA">
field definitions...
    <entity name="testB" query="select * from testB where testB.a_id = '${testA.id}'">
    field definitions...
</entity>
</entity 

,但可以選擇在一個查詢中執行此操作。 我想要達到這個結果:

{"id": "1",
    "LAST_NAME": "Terry",
    "FIRST_NAME": "John",
    "address_home": ["HOME 1","HOME 11","HOME 111"],
    "address_coresp": ["CORESP_1","CORESP_11","CORESP_111"],
    "_version_": 1513905361988354000
    }

提前致謝

檢查您的schema.xml中uniqueKey的值,我懷疑它設置為“ id”:

 <uniqueKey>id</uniqueKey>

因此,每個隨后的id為“ 1”的記錄都將覆蓋最后一條記錄,從而導致僅將id為“ 1”的最后一條記錄保留在索引中。

如果您需要在數據庫中的數據更改時能夠更新Solr中的文檔,則可以使用TableB中的ID或TableA和TableB中ID的組合。 如果不需要更新,則可以將id字段映射到其他Solr字段,並讓Solr自動生成唯一的ID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM