# Not filter not working for me

**URL:** https://discuss.elastic.co/t/not-filter-not-working-for-me/5066
**Category:** Elasticsearch
**Created:** [August 5, 2011, 12:49pm UTC](https://discuss.elastic.co/t/not-filter-not-working-for-me/5066 "2011-08-05T12:49:26Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![marcus](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@marcus](https://discuss.elastic.co/u/marcus)
#### Post date: [August 5, 2011, 12:49pm UTC](https://discuss.elastic.co/t/not-filter-not-working-for-me/5066/1 "2011-08-05T12:49:26Z")

</div>

Hello,

I have been trying out to use Elasticsearch for some weeks and must say it's very easy and usable. But now I've bumped in to my first problem that I can't seem to find a solution for. I'm trying to filter a query on one variable category and one type. Then I try to filter out some ids that I don't want in the query. I have set so the ids are indexed.

The query looks like this:

{  
"filtered" : {  
"query" : {  
"term" : { "category" : "movies" }  
},  
"filter" : {  
"and" : {  
"term" : { "\_type" : "movie" }  
}  
"not" : {  
"term" : { "\_id" : "a123" },  
"term" : { "\_id" : "b123" }  
}  
}  
}  
}

The problem is that it only sends back the ids a123and b123 rather then reducing the query from them. Does anyone have clue what I'm doing wrong?

Cheers,  
Marcus

---

<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: [August 5, 2011, 7:38pm UTC](https://discuss.elastic.co/t/not-filter-not-working-for-me/5066/2 "2011-08-05T19:38:58Z")

</div>

The not filter accepts a single filter, so it can handle a single term  
filter, but if you want some sort of logic combination of filters, then you  
need to wrap those two term filters it in an and/or filter.

On Fri, Aug 5, 2011 at 3:49 PM, marcus [marcus.1.johansson@nokia.com](mailto:marcus.1.johansson@nokia.com) wrote:

> Hello,
> 
> I have been trying out to use Elasticsearch for some weeks and must say  
> it's  
> very easy and usable. But now I've bumped in to my first problem that I  
> can't seem to find a solution for. I'm trying to filter a query on one  
> variable category and one type. Then I try to filter out some ids that I  
> don't want in the query. I have set so the ids are indexed.
> 
> The query looks like this:
> 
> {  
> "filtered" : {  
> "query" : {  
> "term" : { "category" : "movies" }  
> },  
> "filter" : {  
> "and" : {  
> "term" : { "\_type" : "movie" }  
> }  
> "not" : {  
> "term" : { "\_id" : "a123" },  
> "term" : { "\_id" : "b123" }  
> }  
> }  
> }  
> }
> 
> The problem is that it only sends back the ids a123and b123 rather then  
> reducing the query from them. Does anyone have clue what I'm doing wrong?
> 
> Cheers,  
> Marcus
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Not-filter-not-working-for-me-tp3228584p3228584.html](http://elasticsearch-users.115913.n3.nabble.com/Not-filter-not-working-for-me-tp3228584p3228584.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

### Author: ![marcus](https://avatars.discourse-cdn.com/v4/letter/m/85e7bf/32.png) [@marcus](https://discuss.elastic.co/u/marcus)
#### Post date: [August 8, 2011, 12:25pm UTC](https://discuss.elastic.co/t/not-filter-not-working-for-me/5066/3 "2011-08-08T12:25:38Z")

</div>

Ah, got it. Worked like a charm. Thanks.

The not filter accepts a single filter, so it can handle a single term filter, but if you want some sort of logic combination of filters, then you need to wrap those two term filters it in an and/or filter.

On Fri, Aug 5, 2011 at 3:49 PM, marcus \<[marcus.1.johansson@nokia.com](mailto:marcus.1.johansson@nokia.com)\> wrote:

> Hello,
> 
> I have been trying out to use Elasticsearch for some weeks and must say  
> it's  
> very easy and usable. But now I've bumped in to my first problem that I  
> can't seem to find a solution for. I'm trying to filter a query on one  
> variable category and one type. Then I try to filter out some ids that I  
> don't want in the query. I have set so the ids are indexed.
> 
> The query looks like this:
> 
> {  
> "filtered" : {  
> "query" : {  
> "term" : { "category" : "movies" }  
> },  
> "filter" : {  
> "and" : {  
> "term" : { "\_type" : "movie" }  
> }  
> "not" : {  
> "term" : { "\_id" : "a123" },  
> "term" : { "\_id" : "b123" }  
> }  
> }  
> }  
> }
> 
> The problem is that it only sends back the ids a123and b123 rather then  
> reducing the query from them. Does anyone have clue what I'm doing wrong?
> 
> Cheers,  
> Marcus
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Not-filter-not-working-for-me-tp3228584p3228584.html](http://elasticsearch-users.115913.n3.nabble.com/Not-filter-not-working-for-me-tp3228584p3228584.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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:57am UTC](https://discuss.elastic.co/t/not-filter-not-working-for-me/5066/4 "2017-07-06T03:57:58Z")

</div>


