Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to select terms buckets by all values being true
PUT test-bool/
{
"mappings" : {
"_doc" : {
"properties" : {
"my-field" : {
"type" : "boolean"
}, "my-terms": {
"type" : "keyword"
}
}
}
}}
POST test-bool/_doc
{
"my-field": true,
"my-terms": "term1"
}
POST test-bool/_doc
{
"my-field": false,
"my-terms": "term1"
}
POST test-bool/_doc
{
"my-field": true,
"my-terms": "term2"
}
POST test-bool/_doc
{
"my-field": true,
"my-terms": "term2"
}
POST test-bool/_doc
{
"my-field": true,
"my-terms": "term3"
}
POST test-bool/_doc
{
"my-field": true,
"my-terms": "term3"
}
POST test-bool/_doc
{
"my-field": true,
"my-terms": "term3"
}
GET test-bool/_search
{
"size": 0,
"aggs": {
"my-term": {
"terms": {
"field": "my-terms",
"size": 10
},
"aggs": {
"num-true": {
"sum": {
"field": "my-field"
}
},
"my-count": {
"value_count": {
"field": "my-terms"
}
},
"my-filter": {
"bucket_selector": {
"buckets_path": {
"truths": "num-true",
"counts": "my-count"
},
"script": "params.truths == params.counts"
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.