I'm trying to get some counts from Elasticsearch. I have a query:
GET index/_search
{
"aggs": {
"first-metadata": {
"terms": {
"field": "filters.metadata.first-metadata"
}
}
}
}
and as a response I'm getting something like that:
"aggregations": {
"first-metadata": {
"buckets": [
{
"key": 87000,
"doc_count": 2
},
{
"key": 100000,
"doc_count": 1
}
]
}
}
Everything is like I've expected. But the problem is that I have multiple metadata types: first-metadata
, second-metadata
and third-metadata
and I would like to have something like that:
"aggregations": {
"first-metadata": {
"buckets": [
{
"key": 87000,
"doc_count": 2
},
{
"key": 100000,
"doc_count": 1
}
]
},
"second-metadata": {
"buckets": [
{
"key": 5555,
"doc_count": 24
},
{
"key": 2222,
"doc_count": 14
},
{
"key": 3333,
"doc_count": 7
}
]
},
"third-metadata": {
"buckets": [
{
"key": 7777,
"doc_count": 23
},
{
"key": 3333,
"doc_count": 11
}
]
}
}
Is there any way to achieve such results in one aggregation query?
It is very simple
POST index/_search
{
"aggs": {
"first-metadata": {
"terms": {
"field": "filters.metadata.first-metadata"
}
},
"second-metadata": {
"terms": {
"field": "filters.metadata.second-metadata"
}
}
}
}
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