Created
November 14, 2019 15:41
-
-
Save EmilBode/550d3ad44220d1ce57a20dda428b15b5 to your computer and use it in GitHub Desktop.
Reprex for elastic forum on post_filtering inner_hits
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 temp | |
{ | |
"mappings" : { | |
"properties" : { | |
"people" : { | |
"type": "nested", | |
"properties" : { | |
"age" : { | |
"type" : "integer" | |
}, | |
"name" : { | |
"type" : "keyword" | |
} | |
} | |
} | |
} | |
} | |
} | |
PUT temp/_doc/1 | |
{ | |
"people": [ | |
{ | |
"name": "Alice", | |
"age": 30 | |
}, | |
{ | |
"name": "Bernhard", | |
"age": 40 | |
} | |
] | |
} | |
PUT temp/_doc/2 | |
{ | |
"people": [ | |
{ | |
"name": "Carlos", | |
"age": 50 | |
}, | |
{ | |
"name": "Dave", | |
"age": 20 | |
} | |
] | |
} | |
GET temp/_search | |
{ | |
"query": { | |
"nested": { | |
"path": "people", | |
"inner_hits": {}, | |
"query": { | |
"match_all": {} | |
} | |
} | |
}, | |
"aggs": { | |
"people": { | |
"nested": { | |
"path": "people" | |
}, | |
"aggs": { | |
"ages": { | |
"histogram": { | |
"field": "people.age", | |
"interval": 5 | |
} | |
} | |
} | |
} | |
}, | |
"post_filter": { | |
"nested": { | |
"path": "people", | |
"query": { | |
"range": { | |
"people.age": { | |
"lte": 25 | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment