Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ApacheSolr-索引数据_Apache_Solr - Fatal编程技术网

ApacheSolr-索引数据

ApacheSolr-索引数据,apache,solr,Apache,Solr,我有两张桌子:桌子A和桌子B。此表之间存在一对多关系。表A中的一行对应于表B中的多行。我有疑问: 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

我有两张桌子:桌子A和桌子B。此表之间存在一对多关系。表A中的一行对应于表B中的多行。我有疑问:

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
}
只有一个地址结果,而不是三个

my 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中,我将多值设置为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 

字段定义。。。
字段定义。。。

检查schema.xml中uniqueKey的值,我怀疑它设置为“id”:

id
因此,id为“1”的每个后续记录都会覆盖最后一条记录,从而在索引中只保留id为“1”的最后一条记录


如果需要在数据库中的数据更改时更新Solr中的文档,可以使用TableB中的id,或TableA和TableB中id的组合。如果不需要更新,您可以将id字段映射到其他Solr字段,并让Solr自动生成唯一id。

谢谢您的回复。Solr不认为我的记录是唯一的,因为每个记录的id都是相同的。我已经用表B中的id测试了这个解决方案,它看起来不像我想要的。我将不得不使用嵌套实体。 {"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 }
 <uniqueKey>id</uniqueKey>