Suppose I have a document like
doc :{
item: {name: "Movie1", code: "M1"}
}
I can simply use terms
aggregation on item.code and get all the buckets. But, is it possible to use aggregation on item.code
but get the output bucket key to be the value of item.name
PS: I know I could use item.name
in the terms
aggregation, but due the nature of data (the names store vary slightly hence I have to use code), I need to bucket by code
but output key as name
.
Not exactly what you are looking for but it does what you need:
{
"size": 0,
"aggs": {
"whatever": {
"terms": {
"field": "item.code",
"size": 10
},
"aggs": {
"top1": {
"top_hits": {
"size": 1,
"_source": {"exclude": "*"},
"fields": ["item.name"]
}
}
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.