11.05.2016 Views

Apache Solr Reference Guide Covering Apache Solr 6.0

21SiXmO

21SiXmO

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

if split=/ (i.e., you want your JSON input file to be indexed as a single <strong>Solr</strong> document). Note that atomic<br />

updates will cause the field to be out-of-sync with the document.<br />

echo: This is for debugging purpose only. Set it to true if you want the docs to be returned as a response.<br />

Nothing will be indexed.<br />

For example, if we have a JSON file that includes two documents, we could define an update request like this:<br />

curl 'http://localhost:8983/solr/my_collection/update/json/docs'\<br />

'?split=/exams'\<br />

'&f=first:/first'\<br />

'&f=last:/last'\<br />

'&f=grade:/grade'\<br />

'&f=subject:/exams/subject'\<br />

'&f=test:/exams/test'\<br />

'&f=marks:/exams/marks'\<br />

-H 'Content-type:application/json' -d '<br />

{<br />

"first": "John",<br />

"last": "Doe",<br />

"grade": 8,<br />

"exams": [<br />

{<br />

"subject": "Maths",<br />

"test" : "term1",<br />

"marks" : 90},<br />

{<br />

"subject": "Biology",<br />

"test" : "term1",<br />

"marks" : 86}<br />

]<br />

}'<br />

With this request, we have defined that "exams" contains multiple documents. In addition, we have mapped<br />

several fields from the input document to <strong>Solr</strong> fields.<br />

When the update request is complete, the following two documents will be added to the index:<br />

{<br />

}<br />

{<br />

}<br />

"first":"John",<br />

"last":"Doe",<br />

"marks":90,<br />

"test":"term1",<br />

"subject":"Maths",<br />

"grade":8<br />

"first":"John",<br />

"last":"Doe",<br />

"marks":86,<br />

"test":"term1",<br />

"subject":"Biology",<br />

"grade":8<br />

In the prior example, all of the fields we wanted to use in <strong>Solr</strong> had the same names as they did in the input<br />

JSON. When that is the case, we can simplify the request as follows:<br />

<strong>Apache</strong> <strong>Solr</strong> <strong>Reference</strong> <strong>Guide</strong> <strong>6.0</strong><br />

191

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!