在solr
搜索中,不会更新或插入多个对象。请帮帮我。
"materialNames":[
{
"material_id":1,
"description":"Motor Oil",
"business":"",
"residential":"",
"notes":""
},
{
"material_id":2,
"description":"Oil Filters",
"business":"",
"residential":"",
"notes":""
}
]
答案 0 :(得分:4)
您正尝试将嵌入文档插入Solr
请注意:
1>我使用了Solr 4.7.0
2 - ;我已提及Embedded Documents In Solr您可以按照此处提及的步骤进行操作。
或强>
以下是步骤
在solrhome文件夹中创建一个lib文件夹(包含bin
和collection1
个文件夹)
将以下jar文件添加到lib文件夹
- solrjsonchild-0.0.1.jar
- json-simple-1.1.1.jar
您可以从source code获取solrjsonchild-0.0.1.jar
文件(将其转换为jar)或here(路径: /solr-4.9.0-MODIFIED.zip/solr-4.9.0/contrib/solrjsonchild-0.0.1.jar
)
在solrconfig.xml
修改
<requestHandler name="/update" class="com.solrfromscratch.handler.UpdateModifiedRequestHandler">
修改
<requestHandler name="/update/json" class="com.solrfromscratch.handler.UpdateModifiedRequestHandler">
在schema.xml
定义 <fieldType name="json" class="com.solrfromscratch.fields.Json"/>
配置您的字段 <field name="materialNames_json" type="json" indexed="false" stored="true"/>
配置动态字段 <dynamicField name="materialNames.*" type="string" indexed="true" stored="true"/>
注意:嵌入字段名称sholud以_json
结尾,否则会抛出错误Error parsing JSON field value. Unexpected OBJECT_START
运行Solr(我使用了端口8973
)
更新json文档
{"id":"123",
"materialNames_json":[
{
"material_id":1,
"description":"Motor Oil",
"business":"",
"residential":"",
"notes":""
},
{
"material_id":2,
"description":"Oil Filters",
"business":"",
"residential":"",
"notes":""
}
] }
<强>结果:强>
http://localhost:8973/solr/collection1/select?q=*%3A*&wt=json&indent=true
{
"responseHeader": {
"status": 0,
"QTime": 0,
"params": {
"indent": "true",
"q": "*:*",
"_": "1426163321444",
"wt": "json"
}
},
"response": {
"numFound": 1,
"start": 0,
"docs": [
{
"id": "123",
"materialNames.0.residential": "",
"materialNames.0.description": "Motor Oil",
"materialNames.0.material_id": "1",
"materialNames.0.notes": "",
"materialNames.0.business": "",
"materialNames.1.residential": "",
"materialNames.1.description": "Oil Filters",
"materialNames.1.material_id": "2",
"materialNames.1.notes": "",
"materialNames.1.business": "",
"materialNames_json": [
{
"residential": "",
"description": "Motor Oil",
"material_id": 1,
"notes": "",
"business": ""
},
{
"residential": "",
"description": "Oil Filters",
"material_id": 2,
"notes": "",
"business": ""
}
],
"_version_": 1495440547544825900
}
]
}
}
希望这有帮助。