# NOT OR TERM issue?

**URL:** <https://discuss.elastic.co/t/not-or-term-issue/7890>\
**Category:** Elasticsearch\
**Created:** [May 29, 2012, 12:41am UTC](https://discuss.elastic.co/t/not-or-term-issue/7890 "2012-05-29T00:41:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy\_Wick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andy_wick/32/44017_2.png) [@Andy\_Wick](https://discuss.elastic.co/u/Andy_Wick)\
**Post date:** [May 29, 2012, 12:41am UTC](https://discuss.elastic.co/t/not-or-term-issue/7890/1 "2012-05-29T00:41:25Z")

</div>

Trying to add simple NOT capability to my elasticsearch interaction and I'm  
getting strange errors from using NOT outside of an OR statement, which I  
think I'm using correctly from the documentation.

Add just 1 document, no special mapping

curl -XPOST [http://localhost:9200/tests/test/1](http://localhost:9200/tests/test/1) -d '{v1:"test1", v2:"test2"}'

1. My normal OR works ok

curl -XPOST [http://localhost:9200/tests/test/\_search](http://localhost:9200/tests/test/_search) -d ' {"query": {  
"filtered": {"query": {"match\_all": {}},  
"filter": {or: [{"term": {"v1": "test1"}}]}  
} } }'

1. Wrap OR with NOT and get an error  
curl -XPOST [http://localhost:9200/tests/test/\_search](http://localhost:9200/tests/test/_search) -d ' {"query": {  
"filtered": {"query": {"match\_all": {}},  
"filter": {"not": {"or": [{"term": {"v1": "test1"}}]}}  
} } }'

Failed to execute phase [query], total failure; shardFailures  
[CUT]  
nested: QueryParsingException[[tests] [or] filter does not support [v1]];

1. If i wrap the inside of the OR with an AND works fine  
curl -XPOST [http://locahost:9200/tests/test/\_search](http://locahost:9200/tests/test/_search) -d ' {"query": {  
"filtered": {"query": {"match\_all": {}},  
"filter": {"not": {"or": [{"and":[{"term": {"v1": "test0"}}]}]}}  
} } }'

Bug? or are you not allowed to NOT certain things?

Thanks,  
Andy

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frederick_cheung/32/1874_2.png) [@Frederick\_Cheung](https://discuss.elastic.co/u/Frederick_Cheung)\
**Post date:** [May 29, 2012, 1:09pm UTC](https://discuss.elastic.co/t/not-or-term-issue/7890/2 "2012-05-29T13:09:39Z")

</div>

On May 29, 1:41 am, Andy Wick [andyw...@gmail.com](mailto:andyw...@gmail.com) wrote:

> Trying to add simple NOT capability to my elasticsearch interaction and I'm  
> getting strange errors from using NOT outside of an OR statement, which I  
> think I'm using correctly from the documentation.
> 
> Add just 1 document, no special mapping
> 
> curl -XPOSThttp://localhost:9200/tests/test/1-d '{v1:"test1", v2:"test2"}'
> 
> 1. My normal OR works ok
> 
> curl -XPOSThttp://localhost:9200/tests/test/\_search-d ' {"query": {  
> "filtered": {"query": {"match\_all": {}},  
> "filter": {or: [{"term": {"v1": "test1"}}]}  
> } } }'
> 
> 1. Wrap OR with NOT and get an error  
> curl -XPOSThttp://localhost:9200/tests/test/\_search-d ' {"query": {  
> "filtered": {"query": {"match\_all": {}},  
> "filter": {"not": {"or": [{"term": {"v1": "test1"}}]}}  
> } } }'
> 
> Bug? or are you not allowed to NOT certain things?

I've found i\ve needed to do

"filter": {"not": {"filter": {"or": [...]}}}

But I'm not sure why this is needed.

Fred

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 29, 2012, 10:16pm UTC](https://discuss.elastic.co/t/not-or-term-issue/7890/3 "2012-05-29T22:16:45Z")

</div>

Its a bug in the non "filter" wrapping option in not filter, opened an  
issue: [Query DSL: not filter with inner filter that uses array element fails (without the `filter` wrapper) · Issue #1987 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1987).

On Tue, May 29, 2012 at 3:09 PM, Frederick Cheung \<  
[frederick.cheung@gmail.com](mailto:frederick.cheung@gmail.com)\> wrote:

> On May 29, 1:41 am, Andy Wick [andyw...@gmail.com](mailto:andyw...@gmail.com) wrote:
> 
> > Trying to add simple NOT capability to my elasticsearch interaction and  
> > I'm  
> > getting strange errors from using NOT outside of an OR statement, which I  
> > think I'm using correctly from the documentation.
> > 
> > Add just 1 document, no special mapping
> > 
> > curl -XPOSThttp://localhost:9200/tests/test/1-d '{v1:"test1",  
> > v2:"test2"}'
> > 
> > 1. My normal OR works ok
> > 
> > curl -XPOSThttp://localhost:9200/tests/test/\_search-d ' {"query": {  
> > "filtered": {"query": {"match\_all": {}},  
> > "filter": {or: [{"term": {"v1": "test1"}}]}  
> > } } }'
> > 
> > 1. Wrap OR with NOT and get an error  
> > curl -XPOSThttp://localhost:9200/tests/test/\_search-d ' {"query": {  
> > "filtered": {"query": {"match\_all": {}},  
> > "filter": {"not": {"or": [{"term": {"v1": "test1"}}]}}  
> > } } }'
> > 
> > Bug? or are you not allowed to NOT certain things?
> 
> I've found i\ve needed to do
> 
> "filter": {"not": {"filter": {"or": [...]}}}
> 
> But I'm not sure why this is needed.
> 
> Fred

---

<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, 3:26am UTC](https://discuss.elastic.co/t/not-or-term-issue/7890/4 "2017-07-06T03:26:23Z")

</div>


