Skip to content

Instantly share code, notes, and snippets.

@benwtrent
Created February 28, 2019 19:25
Show Gist options
  • Save benwtrent/d23934484674f8ece6b885f11647ad16 to your computer and use it in GitHub Desktop.
Save benwtrent/d23934484674f8ece6b885f11647ad16 to your computer and use it in GitHub Desktop.
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