I have two questions about the query seen on this capture:
How do I order by
value
in thesum_category
field in the results? I userespsize
again in the query but it's not correct as you can see below.Even if I make only an aggregration, why do all the documents come with the result? I mean, if I make a
group by
query in SQL it retrieves only grouped data, but Elasticsearch retrieves all documents as if I made a normal search query. How do I skip them?
Try this:
1). See the note in (2) for what your
sort
is doing. As for ordering the categories by the value of sum_category, see theorder
portion. There appears to be an old and closed issue related to that https://github.com/elastic/elasticsearch/issues/4643 but it worked fine for me with v1.5.2 of Elasticsearch.2). Although you do not have that match_all query, I think that's probably what you are getting results for. And so the sort your specified is actually getting applied to those results. To not get these back, I just have
size: 0
portion.Do you want buckets for all the categories? I noticed you do not have size specified for the main aggregation. That's the
size: 999999
portion.