Skip to content

Instantly share code, notes, and snippets.

@matthuhiggins
Created September 20, 2013 22:33
Show Gist options
  • Save matthuhiggins/6644826 to your computer and use it in GitHub Desktop.
Save matthuhiggins/6644826 to your computer and use it in GitHub Desktop.
nested mapping fields with the same name as the parent are not searchable
curl -XDELETE 127.0.0.1:9200/blog/
curl -XPOST 127.0.0.1:9200/blog/
# An article has a "title" field. Article has a nested mapping of comments, which has the fields "author" and "title".
curl -XPUT 127.0.0.1:9200/blog/article/_mapping -d '
{
"article": {
"properties":{
"title": {
"type": "string",
"analyzed": false
},
"comments": {
"type": "nested",
"properties": {
"title": {
"type": "string",
"analyzed": false
},
"author": {
"type": "string",
"analyzed": false
}
}
}
}
}
}'
curl -XPUT 127.0.0.1:9200/blog/article/42 -d '
{
"title": "red",
"comments": [{"author": "jim", "title": "green"}]
}'
curl -XPOST "http://localhost:9200/blog/_refresh"
# This returns results
curl -XGET 127.0.0.1:9200/blog/article/_search -d '
{
"query": {
"nested": {
"path":"comments",
"filter": {"term":{"author":"jim"}}
}
}
}'
# This does not return results
curl -XGET 127.0.0.1:9200/blog/article/_search -d '
{
"query": {
"nested": {
"path":"comments",
"filter": {"term":{"title":"green"}}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment