Hunter007
Hunter007

Reputation: 3

elasticsearch query LIKE multiple terms with OR

SELECT * FROM tablename WHERE field1 LIKE '%keysearch%' OR field2 LIKE '%keysearch%' OR field3 LIKE '%keysearch%';

How to translate this query to elasticsearch query?

Upvotes: 0

Views: 147

Answers (1)

Olly Cruickshank
Olly Cruickshank

Reputation: 6180

the simplest way to do this is using query_string:

curl -XGET 'http://localhost:9200/index/tablename/_search?pretty' -d '{
  "query": {
    "query_string": { 
         "query":"*keysearch*", 
         "fields": ["field1","field2","field3"]
     }
   }
}'

query_string will use OR by default and will support a wildcard.

However your performance won't be great if using leading and trailing wildcards.

Upvotes: 1

Related Questions