# ElasticSearch Match Phrase Query Not returning expected results

**URL:** <https://discuss.elastic.co/t/elasticsearch-match-phrase-query-not-returning-expected-results/355664>\
**Category:** Elasticsearch\
**Created:** [March 18, 2024, 10:53pm UTC](https://discuss.elastic.co/t/elasticsearch-match-phrase-query-not-returning-expected-results/355664 "2024-03-18T22:53:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhijain](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@abhijain](https://discuss.elastic.co/u/abhijain)\
**Post date:** [March 18, 2024, 10:53pm UTC](https://discuss.elastic.co/t/elasticsearch-match-phrase-query-not-returning-expected-results/355664/1 "2024-03-18T22:53:53Z")

</div>

I have a document with field: "title1" as: "A380 Familiarization".

When I run this query: the search results are empty. The document is not returned as part of the search query results.

```auto
GET index/_search
{
    "from": 0,
    "size": 10,
    "_source":
    [
        "title1"
    ],
    "query":
    {
        "bool":
        {
            "must":
            {
                "bool":
                {
                    "should":
                    [
                        {
                            "multi_match":
                            {
                                "query": "A380 Familiarization",
                                "analyzer": "search_analyzer1",
                                "type": "phrase",
                                "fields":
                                [
                                    "title1"
                                ]
                            }
                        }
                    ]
                }
            }
        }
    },
    "sort":
    [
        {
            "_score": "desc"
        }
    ]
}

```

The field title1 is indexed using a different analyzer:

```auto
  "title1": {
          "type": "text",
          "fields": {
            "raw": {
              "type": "keyword"
            }
          },
          "analyzer": "search_analyzer2"
        }

```

Here is the definition of search\_analyzer2:

```auto
"search_analyzer2": {
             "type": "custom",
             "tokenizer": "standard",
             "filter": [
               "icu_folding",
               "word_delimiter_filter",
               "edge_ngram_filter"
             ],
             "char_filter": [
               "html_strip"
             ]
           }

```

And, here is the definition of search\_analyzer1:

```auto
  "search_analyzer1": {
             "type": "custom",
             "tokenizer": "standard",
             "filter": [
               "icu_folding"
             ],
             "char_filter": [
               "html_strip"
             ]
           }

```

When I run analyze command using both the analyzers, there are overalapping tokens. Both return A380 but still the document is not returned.

```auto
GET index/_analyze
{
  "analyzer": "search_analyzer1",
  "text": "A380"
}

GET index/_analyze
{
  "analyzer": "search_analyzer2",
  "text": "A380"
}

```

Please advise why the document is not returned in the search results?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 18, 2024, 11:20pm UTC](https://discuss.elastic.co/t/elasticsearch-match-phrase-query-not-returning-expected-results/355664/2 "2024-03-18T23:20:30Z")

</div>

What is the output of both \_analyze calls?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 19, 2024, 3:14pm UTC](https://discuss.elastic.co/t/elasticsearch-match-phrase-query-not-returning-expected-results/355664/3 "2024-03-19T15:14:03Z")

</div>

> [@abhijain](#):
>
> `"query": "A380 Familiarization",`

Your search string is not what you showed the analysis for. How is this analyzed using both analyzers? How is the indexed string you are looking to match analyzed?

---

<div class="post-metadata">

**Author:** ![abhijain](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@abhijain](https://discuss.elastic.co/u/abhijain)\
**Post date:** [March 19, 2024, 8:51pm UTC](https://discuss.elastic.co/t/elasticsearch-match-phrase-query-not-returning-expected-results/355664/4 "2024-03-19T20:51:44Z")

</div>

Here is the analyze result for analyzer2:

```auto
GET index/_analyze
{
  "analyzer": "search_analyzer2",
  "text": "A380 Familiarization"
}

{
  "tokens": [
    {
      "token": "a",
      "start_offset": 0,
      "end_offset": 4,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "a3",
      "start_offset": 0,
      "end_offset": 4,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "a38",
      "start_offset": 0,
      "end_offset": 4,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "a380",
      "start_offset": 0,
      "end_offset": 4,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "a",
      "start_offset": 0,
      "end_offset": 1,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "3",
      "start_offset": 1,
      "end_offset": 4,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "38",
      "start_offset": 1,
      "end_offset": 4,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "380",
      "start_offset": 1,
      "end_offset": 4,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "f",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "fa",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "fam",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "fami",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "famil",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "famili",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "familia",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "familiar",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "familiari",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "familiariz",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "familiariza",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "familiarizat",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "familiarizati",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "familiarizatio",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "familiarization",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 2
    }
  ]
}

```

And here is the analyze result for analyzer1:

```auto
GET index/_analyze
{
  "analyzer": "search_analyzer1",
  "text": "A380 Familiarization"
}

{
  "tokens": [
    {
      "token": "a380",
      "start_offset": 0,
      "end_offset": 4,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "familiarization",
      "start_offset": 5,
      "end_offset": 20,
      "type": "<ALPHANUM>",
      "position": 1
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 20, 2024, 8:50pm UTC](https://discuss.elastic.co/t/elasticsearch-match-phrase-query-not-returning-expected-results/355664/5 "2024-03-20T20:50:54Z")

</div>

What if you remove this line?

```auto
"type": "phrase",

```

---

<div class="post-metadata">

**Author:** ![abhijain](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@abhijain](https://discuss.elastic.co/u/abhijain)\
**Post date:** [March 20, 2024, 11:11pm UTC](https://discuss.elastic.co/t/elasticsearch-match-phrase-query-not-returning-expected-results/355664/6 "2024-03-20T23:11:48Z")

</div>

If I remove the "type": "phrase", I get the search results.  
The thing is: I need it to work with type: phrase.  
phrase means exact match. I am using exact terms when searching then why the search results are not getting returned?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 17, 2024, 11:12pm UTC](https://discuss.elastic.co/t/elasticsearch-match-phrase-query-not-returning-expected-results/355664/7 "2024-04-17T23:12:25Z")

</div>

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