Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch match multiple fields

I am recently using elasticsearch in a website. The scenario is, I have to search a string on afield. So, if the field is named as title then my search query was,

"query" :{"match": {"title": my_query_string}}.

But now I need to add another field in it. Let say, category. So i need to find the matches of my string which are in category :some_category and which have title : my_query_string I tried with multi_match. But it does not give me the result i am looking for. I am looking into query filter now. But is there way of adding two fields in such criteria in my match query?

like image 685
salmanwahed Avatar asked Dec 14 '22 23:12

salmanwahed


1 Answers

GET indice/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "title": "title"
          }
        },
        {
          "match": {
            "category": "category"
          }
        }
      ]
    }
  }
}

Replace should with must if desired.

like image 186
Kristaps Karlsons Avatar answered Jan 10 '23 06:01

Kristaps Karlsons