Elasticsearch filter aggregates with a minimum number of documents

I am really new to the elasticsearch world.

Let's say I have nested aggregation in two fields: field1 and field2 :

 { ... aggs: { field1: { terms: { field: 'field1' }, aggs: { field2: { terms: { field: 'field2' } } } } } } 

This piece of code works fine and gives me something like this:

 aggregations: { field1: { buckets: [{ key: "foo", doc_count: 123456, field2: { buckets: [{ key: "bar", doc_count: 34323 },{ key: "baz", doc_count: 10 },{ key: "foobar", doc_count: 36785 }, ... ] },{ key: "fooOO", doc_count: 423424, field2: { buckets: [{ key: "bar", doc_count: 35 },{ key: "baz", doc_count: 2435453 }, ... ] }, ... ] } } 

Now I need to exclude all aggregation results where doc_count less than 1000, and instead:

 aggregations: { field1: { buckets: [{ key: "foo", doc_count: 123456, field2: { buckets: [{ key: "bar", doc_count: 34323 },{ key: "foobar", doc_count: 36785 }, ... ] },{ key: "fooOO", doc_count: 423424, field2: { buckets: [{ key: "baz", doc_count: 2435453 }, ... ] }, ... ] } } 

Is it possible to establish this need for a request body? or do I need to execute a filter on the caller’s layout (in javascript in my case)?

Thanks in advance

+7
aggregation filtering elasticsearch
source share
1 answer

Next time, M'sieur Toph ': RTFM !!!

I feel very stupid: I found anwser in the manual, 30 seconds after the request. I do not delete my question, because it can help, who knows ...

Here is anwser:

You can specify the min_doc_count property in terms aggregation.

He gives you:

 { ... aggs: { field1: { terms: { field: 'field1', min_doc_count: 1000 }, aggs: { field2: { terms: { field: 'field2', min_doc_count: 1000 } } } } } } 

You can also specify a specific minimum score for each level of your aggregation.

What else?:)

+16
source share

All Articles