Having used elastic aggregations for a little bit (and having used Mongo
aggregations previously), I have been finding a couple of things a bit
I am not sure if its because I don't know how to do it properly - or we
missing a feature/enhancement in elastic.
A common thing I want to do is aggregate on field x, but in the result, I
also want field y & z (which are unique for a given x) - there doesn't seem
to be an easy way to do that.
Lets say I have some data:
"id" : "94538ef6-2998-4ddd-be00-1f5dc2654955",
"quantity" : 1234567.2342,
"commodityId" : "0e918fb8-6572-4663-a692-cbebe8aca7f2",
"commodityName" : "Lead",
"ownerId" : "53e0f816-8a0a-4659-b868-c48035676b25",
"ownerName" : "Simon Chan",
"locationId" : "1cdd4bc7-76d9-43fb-ac56-8f555164211a",
"locationName" : "Shenyang - Shenyang Dongbei",
"locationCode" : "W33",
"locationCity" : "Shenyang",
"locationCountry" : "China"
Lets say I want to do a (term) aggregation on ownerId (because its unique,
while ownerName obviously is not) I will get results where the bucket key
is the id. However, what I want to display to the user is the ownerName -
not the id. Looking up the name from the id could be very expensive - but
its also unnecessary because the name will be unique for a given bucket -
we have the info to hand in the index. The same issue if I want to
aggregate by locationId, or commodityId. We dereference the data associated
with an id, so that we can search on them - but also we want to use this
information to create a label for a bucket when we aggregate.
Is there a simple way to retrieve ownerName while aggregating on ownerId?
The only way I know to do this is to:
a) make sure owner name is not_analyzed and
b) do a term subaggregation - which will give only 1 result.
Is there an easier way I have missed?
(FWIW doing the same thing in, say, a Mongo aggregation is simply a matter
of adding the ownerName as a key field - since its unique for a given id,
it wont change the aggregation results - the ownerName info is simply
extracted from the key data in the result).
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to email@example.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/cfcf8e74-06e7-4bf3-8cca-311dd14ccbe2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.