Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can get exact match filter result in Elastic Search

I have one problem regarding elastic search, I want to search the exact match in the filters. For example, If the color filter is applied only "Black" then the elastic search should be returned only "Black" products instead of other products which have Black keywords in their product color like "Black grey". I have tried "match_phrase" instead of "match" but couldn't get anything.

Please check the screenshot of my JSON string: https://www.screencast.com/t/wjCcpfQwTxw

enter image description here Thanks in advance

like image 246
Techleads MobileDevs Avatar asked Oct 24 '25 05:10

Techleads MobileDevs


1 Answers

You can user term query.
For example: 
GET {Your index}/_search
{
    "query": {
        "term": {
            "color.keyword": {
                "value": "Black"
            }
        }
    }
}

It will return the documents which 'color' field equals to Black.If your color field is text type.Remember add '.keyword' after it.
like image 162
user9940960 Avatar answered Oct 26 '25 19:10

user9940960