I have an index with the following mapping:
curl -XPUT "http://localhost:9200/index1" -d'
{
"mappings": {
"movie": {
"properties": {
"people": {
"properties": {
"cast": {
"type": "nested",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
}
}
},
"producers": {
"type": "nested",
"properties": {
"lastName": {
"type": "string"
}
}
}
}
}
}
}
}
}'
Then I put a simple doc in there:
curl -XPOST "http://localhost:9200/index1/movie/" -d'
{
"title": "The Matrix",
"people": {
"cast": [
{
"firstName": "Keanu",
"lastName": "Reeves"
},
{
"firstName": "Laurence",
"lastName": "Fishburne"
}
]
}
}'
Now, this is the interesting part. If I make a nested filter for the firstName
field, it worsk just fine. However, if I do it for lastName it does not work
at all. It seems that because this fields appears in two nested properties I cannot
filter with them:
WORKS:
curl -XPOST "http://localhost:9200/index1/movie/_search" -d'
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"path": "people.cast",
"filter": {
"term": {
"firstName": "keanu"
}
}
}
}
}
}
}'
{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"index1","_type":"movie","_id":"AUzX6wLHdI5sfxoODE5E","_score":1.0,"_source":
{
"title": "The Matrix",
"people": {
"cast": [
{
"firstName": "Keanu",
"lastName": "Reeves"
},
{
"firstName": "Laurence",
"lastName": "Fishburne"
}
]
}
}}]}}
DOESN'T WORK:
curl -XPOST "http://localhost:9200/index1/movie/_search" -d'
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"path": "people.cast",
"filter": {
"term": {
"lastName": "reeves"
}
}
}
}
}
}
}'
{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}%
Is this a bug or I am doing something wrong?