There are lot of questions and answers about this but still didn't get a satisfied answers. Elasticsearch version: 6.5
Index mapping
"_doc": {
"properties": {
"ssid": {
"type": "long"
},
"nested_field": {
"type": "nested"
}
}
}
}
Search query:
{
"query": {
"bool": {
"filter": {
"script": {
"script": "params._source.nested_field.size() > 1"
}
}
}
}
}
Also tried below query but no luck
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "nested_field",
"query": {
"bool": {
"filter": {
"script": {
"script": "params._source.nested_field.size() > 1"
}
}
}
}
}
}
]
}
}
}
Error
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"params._source.nested_field.size() > 1",
" ^---- HERE"
],
"script": "params._source.nested_field.size() > 1",
"lang": "painless"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "testing_index",
"node": "XXXXXXXXXXXXXXXXXXXXXXX",
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"params._source.nested_field.size() > 1",
" ^---- HERE"
],
"script": "params._source.nested_field.size() > 1",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
}
]
},
"status": 500
}
params._source.nested_field return nested array while using in scripted_field but not working in validation query. Documentation are not complete about nested query with painless script.