Elasticsearch terms aggregation based on id field need name field as a display


(Rajadurai) #1

is there anyway that we can buckets based on id and display based on Name?

{
"aggs" : {
"topAdvisors" : {
"terms" : {
"field" : "advRepNum"
}
}
}
}

Output :
"buckets":
[
{
"key": "9813",
"doc_count": 433
},
{
"key": "19076",
"doc_count": 275
},
{
"key": "6877",
"doc_count": 30
},
{
"key": "19347",
"doc_count": 67
}
]

Expected Output:		
		"buckets":
        [
            {
                "key": "John",
                "doc_count": 433
            },
            {
                "key": "Smith",
                "doc_count": 275
            },
            {
                "key": "Tom",
                "doc_count": 30
            },
            {
                "key": "Ben",
                "doc_count": 67
            }
        ]

(Adrien Grand) #2

This is not possible. You would have to perform follow-up requests in order to resolve the name given the id.


(Rajadurai) #3

what should be the followup request to proceed furthur.


(Adrien Grand) #4

You would have to run a term query on the id and look up the name in the returned document.


(Rajadurai) #5

Can you please provide sample _id query with that aggregations.


(system) #6