Hi all,
I'm trying to filter an aggregations.
I created aggregation for nested fields(pipe of id|value) of Badge field. It works good and return me buskets with pipe and doc_count. But I want to filter them to return me only ones that contain word "future". Is it possible?
Index (Badge is nested, value is keyword):
{"id":1, "Badge":[{"id": 5, "value":"analysis of economics"}, {"id": 4, "value":"future of science"}]}
{"id":2, "Badge":[{"id": 3, "value":"future of investments"}, {"id": 2, "value":"solar energy"}]}
{"id":3, "Badge":[{"id": 3, "value":"future of investments"}, {"id": 4, "value":"future of science"}]}
Query:
{
"size": 0,
"aggs": {
"Badge_agg" : {
"nested": {"path": "Badge"},
"aggs": {
"Badge_count": {
"terms": {
"script": { "lang": "painless", "source": "doc['Badge.id'].value + '|' + doc['Badge.value'].value" }
}
}
}
}
}
}
Result (baskets)
"buckets": [
{
"key": "3|future of investments",
"doc_count": 2
},
{
"key": "4|future of science",
"doc_count": 2
},
{
"key": "2|solar energy",
"doc_count": 1
},
{
"key": "5|analysis of economics",
"doc_count": 1
}
]
Desirable result:
"buckets": [
{
"key": "3|future of investments",
"doc_count": 2
},
{
"key": "4|future of science",
"doc_count": 2
}
]
Many thanks