1

SELECT * FROM Customers WHERE City IN ('Paris','London')

How to convert above query in elasticsearch..

3

2 Answers 2

2

You may use terms query

GET _search
{
    "query" : {
        "terms" : {
            "city" : ["Paris", "London"]
        }
    }
}

However, please make sure that your mapping has city marked as not_analyzed

In order to make your searches case insensitive, there are two ways I can think of :

  1. lower case your terms while indexing as well as querying, this is an easy way.
  2. Create a custom analyzer for lowercase the input without tokenizing it. Use match query instead of terms query. Terms query doesn't work on analyzed fields.

A sample lowercase analyzer would look like this :

"analyzer": {
    "lowercase_analyzer": {
        "type": "custom",
        "tokenizer": "keyword",
        "filter": [
            "lowercase",
            "asciifolding"
        ]
    }
    }
Sign up to request clarification or add additional context in comments.

4 Comments

After mapping not_analyzed then search don't work as a case incensitive.How to resolve it..thanks for your reply
Updated the answer for the same.
$results=$client->search([ 'index' => 'morsol', 'type' => 'ms_emp_db', 'body' => [ 'query' => [ "multi_match" => [ "fields" => ["colmun1","column2"], "query" => $searchKeyword, "type" => "phrase_prefix" ] ] ] ]); i am using laravel and elasticsearch.column1 and column2 is not_analyzed..how to search case insensitive.
0

Your query should look like:

The POST request:

http://localhost:9200/Customers/_search? <--assuming customers as your index

and the request BODY:

"query":{  
      "query_string":{  
         "query":"City:(Paris London)"
      }
   }

IN acts like : in ES. Hope this helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.