Filter on query result

Hello, I'm trying to filter out results after executing a nested query, but for some reason it looks like it doesn't get filtered.

I'm using the first query to return me with documents that have at least one event in the date range
that contains the product 1.
Then, from the results of that query I want to filter out the documents that contains the product 2 in any of their event...
I'm using the filter outside of the nested query because, if I understand correctly, if I add it to the nested term and there will be a single event that has only 1 (without 2) then its doc will not be filtered(it will validate the doc). So I'm using a simple filter on the result that will just filter all the docs that contain the string 2.

Is there something that I didn't consider? since in my case there's at least one doc that contains these two product Ids(in different event) and it doesn't get filtered. -> I'm getting the same result count with or without the filter.

Any ideas anyone?

Thanks,

Oren

{
"size" : 0,
"query" : {
"nested" : {
"query" : {
"bool" : {
"must" : [ {
"term" : {
"events.products.product" : "1"
}
}, {
"range" : {
"events.event_time" : {
"from" : "2013-06-02",
"to" : "2013-06-02",
"include_lower" : true,
"include_upper" : true
}
}
} ]
}
},
"path" : "events"
}
},
"filter" : {
"bool" : {
"must_not" : [ {
"term" : {
"events.products.product" : "2"
}
} ]
}
},
"fields" : [ ]
}

Hey,

have you tried a nester filter inside of the filter as well (depends on
your data model of course, which you did not show)?

--Alex

On Mon, Jul 22, 2013 at 11:21 PM, oreno oreno@exelate.com wrote:

Hello, I'm trying to filter out results after executing a nested query,
but
for some reason it looks like it doesn't get filtered.

I'm using the first query to return me with documents that have at least
one
event in the date range
that contains the product 1.
Then, from the results of that query I want to filter out the documents
that
contains the product 2 in any of their event...
I'm using the filter outside of the nested query because, if I understand
correctly, if I add it to the nested term and there will be a single event
that has only 1 (without 2) then its doc will not be filtered(it will
validate the doc). So I'm using a simple filter on the result that will
just
filter all the docs that contain the string 2.

Is there something that I didn't consider? since in my case there's at
least
one doc that contains these two product Ids(in different event) and it
doesn't get filtered. -> I'm getting the same result count with or without
the filter.

Any ideas anyone?

Thanks,

Oren

{
"size" : 0,
"query" : {
"nested" : {
"query" : {
"bool" : {
"must" : [ {
"term" : {
"events.products.product" : "1"
}
}, {
"range" : {
"events.event_time" : {
"from" : "2013-06-02",
"to" : "2013-06-02",
"include_lower" : true,
"include_upper" : true
}
}
} ]
}
},
"path" : "events"
}
},
"filter" : {
"bool" : {
"must_not" : [ {
"term" : {
"events.products.product" : "2"
}
} ]
}
},
"fields" : [ ]
}

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/filter-on-query-result-tp4038474.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Hi, I was able to get the result I needed by using the not filter, although I'm not sure about the performance there. Any thoughts?

{
"size": 0,
"query": {
"nested": {
"query": {
"bool": {
"must": [{
"term": {
"events.products.product": "1772178"
}
},
{
"range": {
"events.event_time": {
"from": "2013-06-01",
"to": "2013-06-03",
"include_lower": true,
"include_upper": true
}
}
}]
}
},
"path": "events"
}
},
"filter": {
"not": {
"query": {
"nested": {
"query": {
"bool": {
"should": {
"term": {
"events.products.product": "1772166"
}
},
"must":
{
"range": {
"events.event_time": {
"from": "2013-06-01",
"to": "2013-06-03",
"include_lower": true,
"include_upper": true
}
}
}
}
},
"path": "events"
}
}
}
}
}