Querying in ES with SQL IN equivalent


(vannya) #1

Hi all,

I would like to search in my ES index all name fields with values
within a list of - as example - ('name1', 'name2', 'name3').
However, I cannot find a simple way to do it! I could use "or"... but
as my list of names grows with time, I could end up doing "or's" with
a huge list of millions!

What I really want is to be able to do something like SQL "IN"
keyword...

Does anyone knows a simpler way to do this?

Thanks in advance!


(vannya) #2

Hi!

I found the solution here:
http://www.elasticsearch.org/guide/reference/query-dsl/terms-query.html

And, then, testing:

curl -XGET http://localhost:9200/my_index/my_type/_search -d '{
"query" : {
"in" : {
"name" : [ "name1", "name2" ]
}
}
}'

I only got the 2 documents I was searching for!

It's solved!

On Wednesday, March 7, 2012 3:36:34 PM UTC, Vania S. wrote:

Hi all,

I would like to search in my ES index all name fields with values
within a list of - as example - ('name1', 'name2', 'name3').
However, I cannot find a simple way to do it! I could use "or"... but
as my list of names grows with time, I could end up doing "or's" with
a huge list of millions!

What I really want is to be able to do something like SQL "IN"
keyword...

Does anyone knows a simpler way to do this?

Thanks in advance!


(system) #3