0

I'm trying to implement search with Elastic Search but having some prob:

What I Have

I'm trying to implementing ElasticSearch I've 2 fields which are :

1) Search term (TextField)

2) City Name (Text Field)

Now what I want here is if user enter both the value then it must search with both (AND Condition) else if user enter search term then it search only search term OR if city then search only City.

What I'm doing

"bool" : {
"should": [
    { 
    "multi_match": {
        "query":   '"'+keyword.toLowerCase()+'"',
        "fields": 
        [ 
            "title", "desc" 
        ]
    }
    }, 
    { 
    "match": 
    { 
        "city": city.toLowerCase() 
    }
    }  
],

}

but it's not working it's searching with OR.

Any help much appreciated.

Thanks in Advance

Randheer

  • You can look into query string for this https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html. – Girdhar Sojitra Oct 04 '17 at 05:26

1 Answers1

0

If you want all conditions to be matched you can use "must" instead of "should".