# Match\_all with filter on percolator not working as expected

**URL:** <https://discuss.elastic.co/t/match-all-with-filter-on-percolator-not-working-as-expected/19377>\
**Category:** Elasticsearch\
**Created:** [August 21, 2014, 12:44am UTC](https://discuss.elastic.co/t/match-all-with-filter-on-percolator-not-working-as-expected/19377 "2014-08-21T00:44:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brad\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brad_smith/32/1333_2.png) [@Brad\_Smith](https://discuss.elastic.co/u/Brad_Smith)\
**Post date:** [August 21, 2014, 12:44am UTC](https://discuss.elastic.co/t/match-all-with-filter-on-percolator-not-working-as-expected/19377/1 "2014-08-21T00:44:03Z")

</div>

First up, I'm using Elasticsearch v1.1.1

I am getting an unexpected result from a percolator. I have broken it down  
to it's simplest parts and am still getting weird results.

Firstly I create a new index with mapping:

PUT /test1  
{  
"mappings": {  
"product": {  
"properties": {  
"subject": {  
"type": "nested",  
"properties": {  
"code": {  
"type": "string"  
}  
}  
}  
}  
}  
}  
}

Then I create two objects for testing:

PUT /test1/product/12345  
{  
"subject": {  
"code": "FA"  
}  
}

PUT /test1/product/12346  
{  
"subject": {  
"code": "BA"  
}  
}

Then I create a query that I would expect to match on the second record  
only:

GET /test1/product/\_search  
{  
"query": {  
"filtered": {  
"query": {  
"match\_all": []  
},  
"filter": {  
"bool": {  
"must\_not": [  
{  
"query": {  
"nested": {  
"path": "subject",  
"query": {  
"prefix": {  
"subject.code": "fa"  
}  
}  
}  
}  
}  
]  
}  
}  
}  
}  
}

So far everything is working as expected. The query returns the second  
record, the first one being excluded by the filter.

I then use the same query to create a percolator:

PUT /test1/.percolator/TEST  
{  
"query": {  
"filtered": {  
"query": {  
"match\_all": []  
},  
"filter": {  
"bool": {  
"must\_not": [  
{  
"query": {  
"nested": {  
"path": "subject",  
"query": {  
"prefix": {  
"subject.code": "fa"  
}  
}  
}  
}  
}  
]  
}  
}  
}  
}  
}

And test against both records:

GET /test1/product/12345/\_percolate

GET /test1/product/12346/\_percolate

They both return the same result:

{  
"took": 1,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"total": 1,  
"matches": [  
{  
"\_index": "test1",  
"\_id": "TEST"  
}  
]  
}

I have tested this without a nested object and it operates as I would  
expect. At first I thought perhaps the match\_all was doing something  
strange to the percolator but when it wasn't a nested object it worked fine.

So my question is, am I missing something obvious? Is this expected  
behaviour and I have just missed it in the documentation, or is this a bug?

I understand I could easily create this query in a different way (and am  
open to some suggestions) however I am building them programatically so the  
bool structure seems the best option. I have also tried using a "not"  
filter with a nested "or" filter with the same result.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/873637e2-9b31-4ad4-bed5-75a729d72190%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/873637e2-9b31-4ad4-bed5-75a729d72190%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Brad\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brad_smith/32/1333_2.png) [@Brad\_Smith](https://discuss.elastic.co/u/Brad_Smith)\
**Post date:** [August 25, 2014, 12:37am UTC](https://discuss.elastic.co/t/match-all-with-filter-on-percolator-not-working-as-expected/19377/2 "2014-08-25T00:37:00Z")

</div>

Should I be submitting this as a bug instead of a question?

On Thursday, 21 August 2014 10:44:03 UTC+10, Brad Smith wrote:

> First up, I'm using Elasticsearch v1.1.1
> 
> I am getting an unexpected result from a percolator. I have broken it down  
> to it's simplest parts and am still getting weird results.
> 
> Firstly I create a new index with mapping:
> 
> PUT /test1  
> {  
> "mappings": {  
> "product": {  
> "properties": {  
> "subject": {  
> "type": "nested",  
> "properties": {  
> "code": {  
> "type": "string"  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> Then I create two objects for testing:
> 
> PUT /test1/product/12345  
> {  
> "subject": {  
> "code": "FA"  
> }  
> }
> 
> PUT /test1/product/12346  
> {  
> "subject": {  
> "code": "BA"  
> }  
> }
> 
> Then I create a query that I would expect to match on the second record  
> only:
> 
> GET /test1/product/\_search  
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all":   
> },  
> "filter": {  
> "bool": {  
> "must\_not": [  
> {  
> "query": {  
> "nested": {  
> "path": "subject",  
> "query": {  
> "prefix": {  
> "subject.code": "fa"  
> }  
> }  
> }  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> So far everything is working as expected. The query returns the second  
> record, the first one being excluded by the filter.
> 
> I then use the same query to create a percolator:
> 
> PUT /test1/.percolator/TEST  
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all":   
> },  
> "filter": {  
> "bool": {  
> "must\_not": [  
> {  
> "query": {  
> "nested": {  
> "path": "subject",  
> "query": {  
> "prefix": {  
> "subject.code": "fa"  
> }  
> }  
> }  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> And test against both records:
> 
> GET /test1/product/12345/\_percolate
> 
> GET /test1/product/12346/\_percolate
> 
> They both return the same result:
> 
> {  
> "took": 1,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "total": 1,  
> "matches": [  
> {  
> "\_index": "test1",  
> "\_id": "TEST"  
> }  
> ]  
> }
> 
> I have tested this without a nested object and it operates as I would  
> expect. At first I thought perhaps the match\_all was doing something  
> strange to the percolator but when it wasn't a nested object it worked fine.
> 
> So my question is, am I missing something obvious? Is this expected  
> behaviour and I have just missed it in the documentation, or is this a bug?
> 
> I understand I could easily create this query in a different way (and am  
> open to some suggestions) however I am building them programatically so the  
> bool structure seems the best option. I have also tried using a "not"  
> filter with a nested "or" filter with the same result.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/80d77619-8bef-4e63-8c9a-37587016462b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/80d77619-8bef-4e63-8c9a-37587016462b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:06am UTC](https://discuss.elastic.co/t/match-all-with-filter-on-percolator-not-working-as-expected/19377/3 "2017-07-06T01:06:48Z")

</div>


