# Nested match must\_not filter doesnot work

**URL:** <https://discuss.elastic.co/t/nested-match-must-not-filter-doesnot-work/13206>\
**Category:** Elasticsearch\
**Created:** [August 13, 2013, 9:36pm UTC](https://discuss.elastic.co/t/nested-match-must-not-filter-doesnot-work/13206 "2013-08-13T21:36:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhishek\_Andhavarapu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhishek_andhavarapu/32/782_2.png) [@Abhishek\_Andhavarapu](https://discuss.elastic.co/u/Abhishek_Andhavarapu)\
**Post date:** [August 13, 2013, 9:36pm UTC](https://discuss.elastic.co/t/nested-match-must-not-filter-doesnot-work/13206/1 "2013-08-13T21:36:11Z")

</div>

All,

I'm trying to run a must\_not filter wrapped in bool

My Mappings  
{  
"response": {  
"properties": {  
"rtext": {  
"type": "nested",  
"properties": {  
"textmapid": {  
"type": "integer"  
},  
"textvalue": {  
"type": "string"  
}  
}  
}  
}  
}  
}

Sample data

{  
"rtext" : [  
{  
"textmapid" : 1,  
"textvalue" : "Jennifer"  
},  
{  
"textmapid" : 2,  
"textvalue" : "Adam"  
}  
]  
}

My Query comes back with hits.

{  
"filter": {  
"nested": {  
"path": "rtext",  
"query": {  
"bool": {  
"must\_not": [  
{  
"match": {  
"rtext.textvalue": "Jennifer"  
}  
},  
{  
"term": {  
"rtext.textmapid": 1  
}  
}  
]  
}  
}  
}  
}  
}

Any help is appreciated,  
Abhishek

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [August 16, 2013, 9:19pm UTC](https://discuss.elastic.co/t/nested-match-must-not-filter-doesnot-work/13206/2 "2013-08-16T21:19:59Z")

</div>

Your query seems to work as expected. You have two nested documents and  
your query inside nested query doesn't match the first one but it matches  
the second one, so you get this record returned. If you don't want a  
document to be returned if at least one of its nested documents matches,  
you need to move must\_not outside of nested:

{  
"filter": {  
"bool": {  
"must\_not": [{  
"nested": {  
"path": "rtext",  
"query": {  
"bool": {  
"must": [{  
"match": {  
"rtext.textvalue": "Jennifer"  
}  
}, {  
"term": {  
"rtext.textmapid": 1  
}  
}]  
}  
}  
}  
}]  
}  
}  
}

On Tuesday, August 13, 2013 5:36:11 PM UTC-4, Abhishek Andhavarapu wrote:

> All,
> 
> I'm trying to run a must\_not filter wrapped in bool
> 
> My Mappings  
> {  
> "response": {  
> "properties": {  
> "rtext": {  
> "type": "nested",  
> "properties": {  
> "textmapid": {  
> "type": "integer"  
> },  
> "textvalue": {  
> "type": "string"  
> }  
> }  
> }  
> }  
> }  
> }
> 
> Sample data
> 
> {  
> "rtext" : [  
> {  
> "textmapid" : 1,  
> "textvalue" : "Jennifer"  
> },  
> {  
> "textmapid" : 2,  
> "textvalue" : "Adam"  
> }  
> ]  
> }
> 
> My Query comes back with hits.
> 
> {  
> "filter": {  
> "nested": {  
> "path": "rtext",  
> "query": {  
> "bool": {  
> "must\_not": [  
> {  
> "match": {  
> "rtext.textvalue": "Jennifer"  
> }  
> },  
> {  
> "term": {  
> "rtext.textmapid": 1  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> Any help is appreciated,  
> Abhishek

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:20am UTC](https://discuss.elastic.co/t/nested-match-must-not-filter-doesnot-work/13206/3 "2017-07-06T02:20:46Z")

</div>


