Query consecutive words using match_phrase elasticsearch works unexpected

268 Views Asked by At

I have the parameter name as a text:

{
  "mappings": {
    "_doc": {
      "properties": {
        "name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
      }
    }
  }
}

Because of the nature of text type in ElasticSearch, matchs every word on the phrase. That's why in some cases I get the next results:

POST /example-tags/_search
{
  "query": {
    "match": {
     "name": "Jordan Rudess was born in 1956"
    }
  }
}

// Results 
{
  "took" : 28,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 2.1596613,
    "hits" : [
      {
        "_index" : "example-tags",
        "_type" : "_doc",
        "_id" : "6101e538bc8ec610aff699e4",
        "_score" : 4.1596613,
        "_source" : {
          "name" : "Jordan Rudess"
        }
      },
       {
        "_index" : "example-tags",
        "_type" : "_doc",
        "_id" : "610123538bc8ec61034ff699e4",
        "_score" : 4.1796613,
        "_source" : {
          "name" : "Alice in Chains"
        }
      },
    ]
  }
}

As you can see, in the text Jordan Rudess was born in 1956 I get the result Alice in Chains just for the word in. I want to avoid this behaviour. If I try:

POST /example-tags/_search
{
  "query": {
    "match_phrase": {
     "name": "Dream Theater keyboardist's Jordan Rudess was born in 1956"
    }
  }
}
// Results
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

So, in the past example I was expecting to get the Jordan Rudess tag name but I get empty results.
I need to get the maximum ocurrences in tag.name of consecutive words in a phrase. How can I achieve that?

0

There are 0 best solutions below