How to prepare search query for OR operator?


(Sam-4) #1

Hi

I want to search any of list(pen, pencil,ink) from index.

I MySQL database we used following query :

select * from field where type in(pen,pencil,ink);

extract what I want to implement with query_String,please help me.

Thanks


(Andrew[.:at:.]DataFeedFile.com) #2

I don't think you can efficiently do OR conditions from simple search
URI.
Better to use Query DSL.
If you are planning to use ES at all you should learn Query DSL there
is no way around it.

here is the link to boolean query DSL:
http://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html

On May 9, 4:19 am, sam mishra.sam...@gmail.com wrote:

Hi

I want to search any of list(pen, pencil,ink) from index.

I MySQL database we used following query :

select * from field where type in(pen,pencil,ink);

extract what I want to implement with query_String,please help me.

Thanks


(Drew Raines) #3

sam wrote:

I want to search any of list(pen, pencil,ink) from index.

I MySQL database we used following query :

select * from field where type in(pen,pencil,ink);

extract what I want to implement with query_String,please help me.

You can do it a couple of ways:

type:pen type:pencil type:ink

Or shorter:

type:(pen pencil ink)

Example:

% curl -s 'localhost:9200/test/_search?q=type:(ink%20pencil)&pretty=1'
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 0.04500804,
"hits" : [ {
"_index" : "test",
"_type" : "foo",
"_id" : "2",
"_score" : 0.04500804, "_source" : {"type":"pencil"}
}, {
"_index" : "test",
"_type" : "foo",
"_id" : "3",
"_score" : 0.04500804, "_source" : {"type":"ink"}
} ]
}

-Drew


(system) #4