Skip to content

Instantly share code, notes, and snippets.

@btiernay
Last active December 21, 2015 22:58
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 btiernay/6378567 to your computer and use it in GitHub Desktop.
Save btiernay/6378567 to your computer and use it in GitHub Desktop.
Example that shows how using a `facet_filter` with a `nested` filter fails to return `nested` facet terms.
#!/bin/bash
#
# Description:
# Example that shows how using a `facet_filter` with a `nested` filter fails to return `nested` facet terms.
# Remove index if it exists already
curl -XDELETE http://localhost:9200/nested
# Create a fresh index
curl -XPOST http://localhost:9200/nested
# Create a nested mapping
curl -XPOST http://localhost:9200/nested/type/_mapping -d '
{
"type":{
"properties":{
"nested1":{
"type":"nested"
}
}
}
}'
# Insert a document with a nested doc
curl -XPOST http://localhost:9200/nested/type/ -d '
{
"nested1":[
{
"x":1
}
]
}'
# Ensure the previous document is searchable
curl -XPOST 'http://localhost:9200/nested/_refresh'
# Demonstrate that the following query with `facet_filter` and `nested` filter fails to return any terms. Note that
# removing the `facet_filter` gives the expected results.
#
# Expected:
# { ... "hits":{"total":1,"max_score":1.0,"hits":[]},"facets":{"nested1":{"_type":"terms","missing":0,"total":1,"other":0,"terms":[{"term":1,"count":1}]}}}
# Actual:
# { ... "hits":{"total":0,"max_score":null,"hits":[]},"facets":{"nested1":{"_type":"terms","missing":0,"total":0,"other":0,"terms":[]}}}
curl -XGET http://localhost:9200/nested/type/_search -d '
{
"size":0,
"query":{
"match_all":{}
},
"facets":{
"nested1":{
"terms":{
"field":"x"
},
"nested":"nested1",
"facet_filter":{
"nested":{
"path":"nested1",
"query":{
"match_all":{}
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment