Query DSL with AND, OR and NOT


(Hugo) #1

Hi all,

I'm trying to create a query that gets all the users that have a
specific name or contact and that live in europe.
To do this I've created the query bellow but I always get the
exception "SearchPhaseExecutionException".

query = {
"filter" : {
"and" : [
{"or" : [
{ "prefix" : { "name" : s_v } },
{ "prefix" : { "contact" : s_v } }
]},
{"term" : { "region" : ''europe" }}
],
"not" : {
"ids" : {
"values" : user_id
}
}
}
}
}

I've tried using "custom_filters_score" and "filtered" but it also
didn't work. I always get the same error.
Can anyone please help me?

Best regards,
Hugo


(Clinton Gormley) #2

Hi Hugo

I'm trying to create a query that gets all the users that have a
specific name or contact and that live in europe.
To do this I've created the query bellow but I always get the
exception "SearchPhaseExecutionException".

Is this the actual JSON that you're passing to ES? If so, it is
invalid, eg you have unquoted s_v.

clint

query = {
"filter" : {
"and" : [
{"or" : [
{ "prefix" : { "name" : s_v } },
{ "prefix" : { "contact" : s_v } }
]},
{"term" : { "region" : ''europe" }}
],
"not" : {
"ids" : {
"values" : user_id
}
}
}
}
}

I've tried using "custom_filters_score" and "filtered" but it also
didn't work. I always get the same error.
Can anyone please help me?

Best regards,
Hugo


(Hugo) #3

Hi Clint,

Sorry, I forgot to tell that s_v is a parameter. user_id is also a
parameter.
I forgot also to tell that I added the 'not' to remove the current
user from the results.

Thanks.
Best regards,
Hugo

On 19 Ago, 11:29, Clinton Gormley cl...@traveljury.com wrote:

Hi Hugo

I'm trying to create a query that gets all the users that have a
specific name or contact and that live in europe.
To do this I've created the query bellow but I always get the
exception "SearchPhaseExecutionException".

Is this the actual JSON that you're passing to ES? If so, it is
invalid, eg you have unquoted s_v.

clint

query = {
"filter" : {
"and" : [
{"or" : [
{ "prefix" : { "name" : s_v } },
{ "prefix" : { "contact" : s_v } }
]},
{"term" : { "region" : ''europe" }}
],
"not" : {
"ids" : {
"values" : user_id
}
}
}
}
}

I've tried using "custom_filters_score" and "filtered" but it also
didn't work. I always get the same error.
Can anyone please help me?

Best regards,
Hugo


(Clinton Gormley) #4

On Fri, 2011-08-19 at 03:38 -0700, Hugo wrote:

Hi Clint,

Sorry, I forgot to tell that s_v is a parameter. user_id is also a
parameter.
I forgot also to tell that I added the 'not' to remove the current
user from the results.

So please can you gist http://gist.github.com/gists the actual JSON that
you're sending to ES.

ta

clint


(Hugo) #5

Hi Clint,

Please check the gist https://gist.github.com/1156912.

Thanks.
Best regards,
Hugo

On 19 Ago, 12:13, Clinton Gormley cl...@traveljury.com wrote:

On Fri, 2011-08-19 at 03:38 -0700, Hugo wrote:

Hi Clint,

Sorry, I forgot to tell that s_v is a parameter. user_id is also a
parameter.
I forgot also to tell that I added the 'not' to remove the current
user from the results.

So please can you gisthttp://gist.github.com/giststhe actual JSON that
you're sending to ES.

ta

clint


(Daniel E) #6

Hugo,

There were a few DSL grammar errors and some structural weirdness in
there. I forked your gist and typed out this. See if it works any
better for you.

On Aug 19, 10:24 am, Hugo hugo....@gmail.com wrote:

Hi Clint,

Please check the gisthttps://gist.github.com/1156912.

Thanks.
Best regards,
Hugo

On 19 Ago, 12:13, Clinton Gormley cl...@traveljury.com wrote:

On Fri, 2011-08-19 at 03:38 -0700, Hugo wrote:

Hi Clint,

Sorry, I forgot to tell that s_v is a parameter. user_id is also a
parameter.
I forgot also to tell that I added the 'not' to remove the current
user from the results.

So please can you gisthttp://gist.github.com/giststheactual JSON that
you're sending to ES.

ta

clint


(Hugo) #7

Hello Clint,

Its working. Thanks! What a great support!!!
I tested your gist but it didn't work at first, but that was because I
was using the version 0.16.
Now I've upgraded to 0.17.2 and its working fine.

Thanks again!
Best regards,
Hugo

On 19 Ago, 15:43, Daniel E deinspan...@gmail.com wrote:

Hugo,

There were a few DSL grammar errors and some structural weirdness in
there. I forked your gist and typed out this. See if it works any
better for you.https://gist.github.com/1156942

On Aug 19, 10:24 am, Hugo hugo....@gmail.com wrote:

Hi Clint,

Please check the gisthttps://gist.github.com/1156912.

Thanks.
Best regards,
Hugo

On 19 Ago, 12:13, Clinton Gormley cl...@traveljury.com wrote:

On Fri, 2011-08-19 at 03:38 -0700, Hugo wrote:

Hi Clint,

Sorry, I forgot to tell that s_v is a parameter. user_id is also a
parameter.
I forgot also to tell that I added the 'not' to remove the current
user from the results.

So please can you gisthttp://gist.github.com/giststheactualJSON that
you're sending to ES.

ta

clint


(system) #8