在 Solr 中搜索多个未更新的对象
In Solr search multiple objects not updated
在solr
中搜索多个对象未更新或插入。请帮助我。
"materialNames":[
{
"material_id":1,
"description":"Motor Oil",
"business":"",
"residential":"",
"notes":""
},
{
"material_id":2,
"description":"Oil Filters",
"business":"",
"residential":"",
"notes":""
}
]
您正在尝试将嵌入式文档插入 Solr
注意:
1> 我用过Solr 4.7.0
2> 我已经提到了 Embedded Documents In Solr 你可以按照这里提到的步骤进行操作。
或
步骤如下
第 1 步:
在您的 solrhome 文件夹中创建一个 lib 文件夹(其中包含 bin
和 collection1
文件夹)
将以下jar文件添加到lib文件夹
- solrjsonchild-0.0.1.jar
- json-simple-1.1.1.jar
您可以从 source code(convert it into jar) or here(路径:/solr-4.9.0-MODIFIED.zip/solr-4.9.0/contrib/solrjsonchild-0.0.1.jar
)
获取 solrjsonchild-0.0.1.jar
文件
第 2 步:
在 solrconfig.xml
修改
<requestHandler name="/update" class="com.solrfromscratch.handler.UpdateModifiedRequestHandler">
修改
<requestHandler name="/update/json" class="com.solrfromscratch.handler.UpdateModifiedRequestHandler">
第 3 步:
在 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"/>
注意:内嵌字段名必须以_json
结尾否则会报错Error parsing JSON field value. Unexpected OBJECT_START
第 4 步:
运行 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
}
]
}
}
希望这对您有所帮助。
在solr
中搜索多个对象未更新或插入。请帮助我。
"materialNames":[
{
"material_id":1,
"description":"Motor Oil",
"business":"",
"residential":"",
"notes":""
},
{
"material_id":2,
"description":"Oil Filters",
"business":"",
"residential":"",
"notes":""
}
]
您正在尝试将嵌入式文档插入 Solr
注意:
1> 我用过Solr 4.7.0
2> 我已经提到了 Embedded Documents In Solr 你可以按照这里提到的步骤进行操作。
或
步骤如下
第 1 步:
在您的 solrhome 文件夹中创建一个 lib 文件夹(其中包含 bin
和 collection1
文件夹)
将以下jar文件添加到lib文件夹
- solrjsonchild-0.0.1.jar
- json-simple-1.1.1.jar
您可以从 source code(convert it into jar) or here(路径:/solr-4.9.0-MODIFIED.zip/solr-4.9.0/contrib/solrjsonchild-0.0.1.jar
)
solrjsonchild-0.0.1.jar
文件
第 2 步:
在 solrconfig.xml
修改
<requestHandler name="/update" class="com.solrfromscratch.handler.UpdateModifiedRequestHandler">
修改
<requestHandler name="/update/json" class="com.solrfromscratch.handler.UpdateModifiedRequestHandler">
第 3 步:
在 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"/>
注意:内嵌字段名必须以_json
结尾否则会报错Error parsing JSON field value. Unexpected OBJECT_START
第 4 步:
运行 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
}
]
}
}
希望这对您有所帮助。