I want to do something like this, use script_fields to show the length of comments.
{
"script_fields" : {
"comments" : {
"script" : "doc['comments'].values.size()"
}
}
}
but comments is a nested type. which looks like
{
"comments": [
{
"k": "2016-01-06T00:00:03",
"v": "v1 "
},
{
"k": "2016-01-06T00:00:04",
"v": "v2"
}
]
}
so I want to know "how to use "script fields" on nested type in ElasticSearch?".
The nested type is a specialised version of the object data type that allows arrays of objects to be indexed in a way that they can be queried independently of each other.
When a packed class contains an instance field that is a packed type, the data for that field is packed directly into the containing class. The field is known as a nested field .
This script should work:
"script_fields": {
"custom_field": {
"script": {
"lang": "painless",
"source": "params['_source']['comments'].size()"
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With