I have multiple elastic documents, with fields "cityId", "cityName". I want to count occurrences of documents with specific "cityId" and "cityName".
Aggregation query to fetch cityId and count:
GET _search
{
"aggs": {
"CityIdCount": {
"terms": {
"field": "cityId",
"size": 0
}
}
},
"query": {
"bool": {
"must": [
...........................
This is the existing query and it gives the result as (key as cityId and doc_count as number of occurrences: { "key": 40, "doc_count": 4906 },
This is query i tried to fetch (cityId,cityName,doc_count) and it gives the result as (key as cityName and doc_count as number of occurrences of that name: { "key": "Thane", "doc_count": 4906 }
GET _search
{
"aggs": {
"CityIdCount": {
"terms": {
"field": "cityId",
"field": "cityName",
"size": 0
}
}
},
"query": {
"bool": {
"must": [
..............................
I want all together, example: "cityId","cityName","doc_count".
What would be the correct query for that?