Skip to content

Instantly share code, notes, and snippets.

@EmilBode
Created November 14, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EmilBode/550d3ad44220d1ce57a20dda428b15b5 to your computer and use it in GitHub Desktop.
Save EmilBode/550d3ad44220d1ce57a20dda428b15b5 to your computer and use it in GitHub Desktop.
Reprex for elastic forum on post_filtering inner_hits
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