11.05.2016 Views

Apache Solr Reference Guide Covering Apache Solr 6.0

21SiXmO

21SiXmO

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

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

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

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

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

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

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

'&f=/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 />

In this example, we simply named the field paths (such as /exams/test). <strong>Solr</strong> will automatically attempt to add<br />

the content of the field from the JSON input to the index in a field with the same name.<br />

Note that if you are not working in Schemaless Mode, where fields that don't exist will be created on the<br />

fly with <strong>Solr</strong>'s best guess for the field type, documents may get rejected if the fields do not exist in the<br />

schema before indexing.<br />

Wildcards<br />

Instead of specifying all the field names explicitly, it is possible to specify wildcards to map fields automatically.<br />

There are two restrictions: wildcards can only be used at the end of the json-path, and the split path cannot<br />

use wildcards. A single asterisk "*" maps only to direct children, and a double asterisk "**" maps recursively to all<br />

descendants. The following are example wildcard path mappings:<br />

f=$FQN:/**: maps all fields to the fully qualified name ( $FQN) of the JSON field. The fully qualified<br />

name is obtained by concatenating all the keys in the hierarchy with a period (.) as a delimiter. This is<br />

the default behavior if no f path mappings are specified.<br />

f=/docs/*: maps all the fields under docs and in the name as given in json<br />

f=/docs/**: maps all the fields under docs and its children in the name as given in json<br />

f=searchField:/docs/*: maps all fields under /docs to a single field called ‘searchField’<br />

f=searchField:/docs/**: maps all fields under /docs and its children to searchField<br />

With wildcards we can further simplify our previous example as follows:<br />

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

192

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

Saved successfully!

Ooh no, something went wrong!