Created
February 28, 2019 19:25
-
-
Save benwtrent/d23934484674f8ece6b885f11647ad16 to your computer and use it in GitHub Desktop.
How to select terms buckets by all values being true
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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