Description
The script fields support in the search API to allow to extract source elements. The extract element (and its "tree" of data) is then streamed back to the user. Here is an example:
{
"query" : { "match_all" : {} },
"script_fields" : {
"test1" : { "script" : "_source.obj1.arr" }
}
}
Note the _source
keyword here to navigate the json like model.
Its important to understand the difference between doc['my_field'].value
and _source.my_field
. The first, using the doc
keyword, will cause the terms for that field to be loaded to memory (cached), which will result in faster execution, but more memory consumption. Also, it only allows for simple valued fields (can't return a json object from it).
The _source
on the other hand causes the source to be loaded, parsed, and then only the relevant part of the json is returned.
Since its a script, logic can also be applied here.