Skip to content

Instantly share code, notes, and snippets.

@brusic
Created November 10, 2014 19:48
Show Gist options
  • Select an option

  • Save brusic/81e1552ffd49a1f6a7aa to your computer and use it in GitHub Desktop.

Select an option

Save brusic/81e1552ffd49a1f6a7aa to your computer and use it in GitHub Desktop.
Nested aggregation issue
curl -XPUT localhost:9200/test -d '{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
}
},
"mappings": {
"test" : {
"properties" : {
"offers" : {
"type" : "nested",
"properties": {
}
}
}
}
}
}
'
curl -XPUT localhost:9200/test/test/1 -d '
{
"name" : "foo",
"offers" : [
{
"ID" : 1
}
]
}
'
curl -XPUT localhost:9200/test/test/2 -d '
{
"name" : "bar",
"offers" : [
{
"ID" : 2
}
]
}
'
curl -XPUT localhost:9200/test/test/3 -d '
{
"name" : "baz",
"offers" : [
{
"ID" : 1
},
{
"ID" : 2
}
]
}
'
POST test/test/_search
{
"size": 0,
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"path": "offers",
"filter": {
"term": {
"offers.ID": 1
}
}
}
}
}
},
"aggregations": {
"Attempt1": {
"nested": {
"path": "offers"
},
"aggs": {
"ID": {
"terms": {
"field": "offers.ID"
}
}
}
},
"FilteredAttempt2": {
"filter": {
"nested": {
"path": "offers",
"filter": {
"term": {
"offers.ID": 1
}
}
}
},
"aggs": {
"NestedID": {
"nested": {
"path": "offers"
},
"aggs": {
"CatalogID": {
"terms": {
"field": "offers.ID"
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment