How to get the Match Type in Elasticsearhc response?


(Santoshkumar) #1

Hi Team,

In Elasticsearch we have types of matches like "Fuzzy", "Exact" etc.....
is there any way that will get to know which type of match has happened for request query, in the elasticsearch response?

Thanks in advance


(David Pilato) #2

You can named your queries. Like this: https://gist.github.com/dadoonet/5179ee72ecbf08f12f53d4bda1b76bab#file-search_kibana_console-txt-L362-L457

GET user/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "name": {
              "query" : "david pilato",
              "_name": "phrase on name",
              "boost": 8.0
            }
          }
        },
        {
          "match": {
            "name": {
              "query": "david pilato",
              "operator": "and", 
              "_name": "all terms on name",
              "boost": 2.0
            }
          }
        },
        {
          "match": {
            "name": {
              "query": "david pilato",
              "operator": "or", 
              "_name": "at least one term on name",
              "boost": 1.8
            }
          }
        },
        {
          "match": {
            "name": {
              "query": "david pilato",
              "fuzziness": 2,
              "_name": "fuzzy on name",
              "boost": 1.0
            }
          }
        },
        {
          "match_phrase": {
            "comments": {
              "query" : "david pilato",
              "_name": "phrase on comments",
              "boost": 0.9
            }
          }
        },
        {
          "match": {
            "comments": {
              "query": "david pilato",
              "operator": "and", 
              "_name": "all terms on comments",
              "boost": 0.8
            }
          }
        },
        {
          "match": {
            "comments": {
              "query": "david pilato",
              "operator": "or", 
              "_name": "at least one term on comments",
              "boost": 0.7
            }
          }
        },
        {
          "match": {
            "comments.synonyms": {
              "query": "david pilato",
              "_name": "synonyms on comments",
              "boost": 0.6
            }
          }
        },
        {
          "match": {
            "comments": {
              "query": "david pilato",
              "fuzziness": 2,
              "_name": "fuzzy on comments",
              "boost": 0.2
            }
          }
        }
      ]
    }
  }
}

(Santoshkumar) #3

Could you please explain it briefly? requirement is when i fire a request to elasticsearch, if a word is matched, i wanted the match type in elasticsearch response...


(David Pilato) #4

Did you try the example I linked to?


(Santoshkumar) #5

yes i tried.. But the scenario you have explained above, hints about which incoming request is matched not about the which match has happened with document in the elasticsearch.


(David Pilato) #6

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.


(Santoshkumar) #7

@dadoonet Thanks for the explaination, i was able to understand the query, it suits my requirement.


(system) #8

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.