Skip to content

Instantly share code, notes, and snippets.

@salami-art
Created January 25, 2021 17:30
Show Gist options
  • Save salami-art/8ab9807019ab8af77de096d6ff7920fe to your computer and use it in GitHub Desktop.
Save salami-art/8ab9807019ab8af77de096d6ff7920fe to your computer and use it in GitHub Desktop.
{
"query": {
// ...
},
"aggs": {
"uniq": {
"nested": {
"path": "nested_object"
},
"aggs": {
"unique_vals": {
"terms": {
"size": 5,
"order": {
"_key": "asc"
},
"script": {
"source": """
if(doc['nested_object.name.keyword'].value != null && doc['nested_object.id'].value != null){
if(doc['main_source_field'].value == 'MyValye'){
return 'A'
}
else
{
return 'B'
}
}
""",
"lang": "painless"
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment