In solr
search multiple objects are not updated or inserted. Please help me.
"materialNames":[
{
"material_id":1,
"description":"Motor Oil",
"business":"",
"residential":"",
"notes":""
},
{
"material_id":2,
"description":"Oil Filters",
"business":"",
"residential":"",
"notes":""
}
]
You are trying to insert Embedded document into Solr
Note that:
1> I have used Solr 4.7.0
2> I have referred Embedded Documents In Solr you can follow the steps mentioned in this.
OR
Below are the steps
Step 1:
Create a lib folder in your solrhome folder( which has bin
and collection1
folders)
Add below jar files to lib folder
- solrjsonchild-0.0.1.jar
- json-simple-1.1.1.jar
You can get solrjsonchild-0.0.1.jar
file from source code(convert it into jar) or here(path:/solr-4.9.0-MODIFIED.zip/solr-4.9.0/contrib/solrjsonchild-0.0.1.jar
)
Step 2:
On solrconfig.xml
modify
<requestHandler name="/update" class="com.solrfromscratch.handler.UpdateModifiedRequestHandler">
modify
<requestHandler name="/update/json" class="com.solrfromscratch.handler.UpdateModifiedRequestHandler">
Step 3:
On schema.xml
Define <fieldType name="json" class="com.solrfromscratch.fields.Json"/>
Configure your field <field name="materialNames_json" type="json" indexed="false" stored="true"/>
Configure a dynamic field <dynamicField name="materialNames.*" type="string" indexed="true" stored="true"/>
Note: Embedded field name sholud be end with _json
otherwise it will throw error Error parsing JSON field value. Unexpected OBJECT_START
Step 4:
Run Solr (I have used port 8973
)
update json document
{"id":"123",
"materialNames_json":[
{
"material_id":1,
"description":"Motor Oil",
"business":"",
"residential":"",
"notes":""
},
{
"material_id":2,
"description":"Oil Filters",
"business":"",
"residential":"",
"notes":""
}
] }
Result:
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
}
]
}
}
Hope this helps.