1

I got two ways to aggs my data.

First, i filter mysql data and aggs it

Second ,i aggs data which is filtered in aggs. as below:

I found different result and I don't know why.

Anyone can explain it ?

case 1

case 2

1 Answer 1

4

From the Docs

By default, aggregations operate in the same scope as the query. Put another way, aggregations are calculated on the set of documents that match your query.

so in the first case, you are getting documents which match your criteria of "site_id" : 1167639 and then aggregation is performed on those documents.

In the second case, you have not specified any query so by default it is match_all query and you get back all the documents in your hits which is 65773792. Then you use filter to narrow down your aggregation criteria.

2
  • 1
    Briefly, in first case OP narrows down results and then aggregates, in second query OP aggregates EVERYTHING and then filters aggs, which is obiviously going to run slower. Commented Nov 27, 2015 at 9:38
  • in second query OP aggregates EVERYTHING and then filters aggs !!! I got it . I thought that in second case query is "match_all" ,and filter in aggs should filter its result !!!
    – Leo
    Commented Nov 29, 2015 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.