I am using nested query with should clauses in elasticsearch 2.3.2
GET shop/customer/_search
{
"from": 0,
"size": 25,
"query": {
"bool": {
"must": [
{
"nested": {
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "london",
"fields": [
"address.city",
"address.street"
]
}
},
{
"term": {
"address.postcode": "123"
}
}
]
}
},
"path": "address"
}
}
]
}
}
}
It works fine but when I add a filter clause to the bool query - I expect this to return only a subset of previous results. However it returns more results - all documents with given address.type, ignoring the should clauses:
GET shop/customer/_search
{
"from": 0,
"size": 25,
"query": {
"bool": {
"must": [
{
"nested": {
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "london",
"fields": [
"address.city",
"address.street"
]
}
},
{
"term": {
"address.postcode": "123"
}
}
],
"filter": [
{
"terms": {
"address.type": [
"4b4372b7"
]
}
}
]
}
},
"path": "address"
}
}
]
}
}
}
I checked the same with not nested query and it works as I'd expected. The should queries return only documents that contains address and adding filter returns subset of this results matching filter.