Restricting Bucket Aggregation to Certain Values

I want to know if it is possible to filter the contents of an aggregation
rather than just the documents returned by the query. For instance, I have
a set of documents that have an array property called related concepts. I
want to count the number of documents for each related concept that meet my
search query. The resulting bucket looks like this:

"related_concepts": {
"buckets": [
{
"key": "foo",
"doc_count": 3821
},
{
"key": "bar",
"doc_count": 3803
},
{
"key": "other",
"doc_count": 23
}
]
}

Now imagine that there are 2,000 related concepts, however, using a graph
database I know I'm interested in a specific 5 or 6. Using the example
above, let's say for a specific result set I want to return the bucket
counts only for the terms "foo" and "other" but NOT include "bar" or any
other buckets. Sort of like a SQL WHERE or HAVING clause.

I tried adding a filter to the aggregation, but it only seemed to filter
the numbers for the aggregations, not restrict which buckets are actually
displayed.

I found this for
2.0 https://github.com/elasticsearch/elasticsearch/issues/8110, and looks
like it might solve my problem eventually (not in time for deadlines!), but
my use case is pretty simple. Is there anything I can do in the current
version of Elasticsearch to make this work? Am I overlooking something?

Thanks!

--
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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/cb4d25de-825b-4c2f-9434-86419e5aa3ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi,

Take a look at the includes/excludes feature on the terms aggregation. I
think it should help with what you are trying to achieve.

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_filtering_values

Colin

On Monday, 8 December 2014 08:10:05 UTC, William Bowen wrote:

I want to know if it is possible to filter the contents of an aggregation
rather than just the documents returned by the query. For instance, I have
a set of documents that have an array property called related concepts. I
want to count the number of documents for each related concept that meet my
search query. The resulting bucket looks like this:

"related_concepts": {
"buckets": [
{
"key": "foo",
"doc_count": 3821
},
{
"key": "bar",
"doc_count": 3803
},
{
"key": "other",
"doc_count": 23
}
]
}

Now imagine that there are 2,000 related concepts, however, using a graph
database I know I'm interested in a specific 5 or 6. Using the example
above, let's say for a specific result set I want to return the bucket
counts only for the terms "foo" and "other" but NOT include "bar" or any
other buckets. Sort of like a SQL WHERE or HAVING clause.

I tried adding a filter to the aggregation, but it only seemed to filter
the numbers for the aggregations, not restrict which buckets are actually
displayed.

I found this for 2.0
https://github.com/elasticsearch/elasticsearch/issues/8110, and looks
like it might solve my problem eventually (not in time for deadlines!), but
my use case is pretty simple. Is there anything I can do in the current
version of Elasticsearch to make this work? Am I overlooking something?

Thanks!

--
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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5bb64118-b4d5-4f47-8c72-530040083381%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Wow, this looks like exactly what I'm looking for. But I swear I spent most
of last month scouring documentation. Is this a relatively new feature? Or
am I just thick? Thanks, either way!

On Mon, Dec 8, 2014 at 3:20 AM, Colin Goodheart-Smithe <
colin.goodheart-smithe@elasticsearch.com> wrote:

Hi,

Take a look at the includes/excludes feature on the terms aggregation. I
think it should help with what you are trying to achieve.

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_filtering_values

Colin

On Monday, 8 December 2014 08:10:05 UTC, William Bowen wrote:

I want to know if it is possible to filter the contents of an aggregation
rather than just the documents returned by the query. For instance, I have
a set of documents that have an array property called related concepts. I
want to count the number of documents for each related concept that meet my
search query. The resulting bucket looks like this:

"related_concepts": {
"buckets": [
{
"key": "foo",
"doc_count": 3821
},
{
"key": "bar",
"doc_count": 3803
},
{
"key": "other",
"doc_count": 23
}
]
}

Now imagine that there are 2,000 related concepts, however, using a graph
database I know I'm interested in a specific 5 or 6. Using the example
above, let's say for a specific result set I want to return the bucket
counts only for the terms "foo" and "other" but NOT include "bar" or any
other buckets. Sort of like a SQL WHERE or HAVING clause.

I tried adding a filter to the aggregation, but it only seemed to filter
the numbers for the aggregations, not restrict which buckets are actually
displayed.

I found this for 2.0 https://github.com/elasticsearch/elasticsearch/
issues/8110, and looks like it might solve my problem eventually (not in
time for deadlines!), but my use case is pretty simple. Is there anything I
can do in the current version of Elasticsearch to make this work? Am I
overlooking something?

Thanks!

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/SR2Yb-Q2zB8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/5bb64118-b4d5-4f47-8c72-530040083381%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/5bb64118-b4d5-4f47-8c72-530040083381%40googlegroups.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.

--
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 elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAEi1X1SPbCXB8vAK-BtgGLYTbHYu5JuWxhEu8RiU-AFzAxNbQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.