Not filter not working for me


(marcus) #1

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


(Shay Banon) #2

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 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
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(marcus) #3

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> 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
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(system) #4