1

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

How to convert above query in elasticsearch..

Nirdesh
  • 174
  • 2
  • 8
  • Have a look at [this](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html#query-dsl-terms-query)! – avr Feb 24 '17 at 08:21
  • Like this: https://stackoverflow.com/questions/16255416/query-with-multiple-values-on-a-property-with-one-value-in-elasticsearch – paqash Feb 24 '17 at 09:14
  • 1
    Possible duplicate of [Query with multiple values on a property with one value in Elasticsearch](http://stackoverflow.com/questions/16255416/query-with-multiple-values-on-a-property-with-one-value-in-elasticsearch) – paqash Feb 24 '17 at 09:15

2 Answers2

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"
        ]
    }
    }
Rahul
  • 15,979
  • 4
  • 42
  • 63
  • After mapping not_analyzed then search don't work as a case incensitive.How to resolve it..thanks for your reply – Nirdesh Feb 27 '17 at 06:51
  • Updated the answer for the same. – Rahul Feb 27 '17 at 07:04
  • $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. – Nirdesh Feb 28 '17 at 11:40
  • Please refer to : http://stackoverflow.com/questions/24036708/elasticsearch-map-case-insensitive-to-not-analyzed-documents – Rahul Mar 01 '17 at 03:35
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!

Kulasangar
  • 9,046
  • 5
  • 51
  • 82