Can I control buckets based on ranges of values?

I'm using ElasticSearch 2.4.x, and I've been through the documents and couldn't find anything that addresses the need I have. I'm trying to provide a faceted search facility on my website with counts for the documents that would potentially match the new criteria. Most of what I want is pretty straightforward and the documentation was very helpful. However, I have one facet that's giving me a bit of trouble.

I have a document called "Teachings" that can reference 0..n "Devotional" documents. I have a field "numberOfDevotionals" that has a count of the devotionals that reference that teaching. It's great for providing more detailed summary information in the listing. However, for my aggregation I just want 2 buckets: "0" and "1 or more" for this stat.

I have a query like this:

</>
POST http://localhost:9200/my-index/teachings/_search?pretty
{
"size": 3,
"sort": [ { "endDate": { "order": "desc" } } ],
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [
{
"term": { "releasableTo": "Member" }
}
]
}
}
}
},
"aggs": {
"teachers": {
"terms": { "field": "teacher.id", "size": 500 }
},
"audio": {
"terms": { "field": "hasAudio" }
},
"transcript": {
"terms": { "field": "hasTranscript" }
},
"landmark": {
"terms": { "field": "isLandmark" }
},
"devotionals": {
"terms": { "field": "numberOfDevotionals", "size": 100 }
}
}
}
</>

For the "devotionals" aggregation, I want to control the resolution of the buckets. Right now I get different counts (separate buckets for 0-10) so I would have to count up all the buckets that has a key greater than "0". I would rather this be a bucket for "0" and a second bucket for all the rest.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.