Hey Adrien,

Say I have two fields in my index with values: 

genre = {Action, Adventure}
actor = {Tom Cruise, Jason Statham}

I'm looking for a way to get the distinct combinations of values with doc 
counts, so I use a sub-aggregation:
"aggs":{
    "genreAgg": {
         "terms": {
             "field": "genre"
         },
         "aggs": {
             "actorAgg": {
                 "terms": {
                     "field": "actor"
                 },
                 "aggs": {
                     "measureAgg": { "sum": { "field" : "docCount"} }
                 }
             }     
         }
    }
}

When I get the data back, I flatten it into a CSV format:
Action, Tom Cruise, 50
Adventure, Tom Cruise, 40
Action, Jason Statham, 20
Adventure, Jason Statham, 40

My question is, is there a better way to do this?  I'm not entirely worried 
about recursively flattening the data.  My point of interest is:
1. Performance - My top aggregation may not be the one with the lowest 
cardinality, can ES handle that for me?
2. Sorting & Limiting - I have to fetch all the data for these fields.  Say 
I want to "sort by actor, limit 1".  Where do you apply the sort?  It can't 
be on the genre field.  Actor's field seems logical, but I still can't 
limit the genre field at all.  Fetching all the data and then flattening 
works because I can sort correctly then limit.

I have seen that you can use script fields to return back single rows.  But 
can you sort and limit by a script field?

-- 
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 protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/28b210de-9822-4967-a95a-c5f74f426ff9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to