# Match phrase prefix query stopped working for multiple terms after 7.10.2

**URL:** https://discuss.elastic.co/t/match-phrase-prefix-query-stopped-working-for-multiple-terms-after-7-10-2/272293
**Category:** Elasticsearch
**Created:** [May 6, 2021, 12:42pm UTC](https://discuss.elastic.co/t/match-phrase-prefix-query-stopped-working-for-multiple-terms-after-7-10-2/272293 "2021-05-06T12:42:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Sleepy\_Panda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sleepy_panda/32/78663_2.png) [@Sleepy\_Panda](https://discuss.elastic.co/u/Sleepy_Panda)
#### Post date: [May 6, 2021, 12:42pm UTC](https://discuss.elastic.co/t/match-phrase-prefix-query-stopped-working-for-multiple-terms-after-7-10-2/272293/1 "2021-05-06T12:42:32Z")

</div>

Issue: search using [match\_phrase\_prefix](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html) does not return results for queries which consist of multiple terms, e.g. "Additional HTTP".

ElasticSearch 7.10.2: document is returned when searching "Additional HTTP"  
ElasticSearch 7.11.1, 7.11.2, 7.12.1: no documents returned when searching "Additional HTTP"; document is returned when searching "Additional" (single term).

Minimal example:

Create index with custom analyzer:

```auto
PUT /test
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas" : "0",
    "analysis" : {
          "analyzer" : {
            "custom_analyzer" : {
              "filter" : [
                "lowercase"
              ],
              "type" : "custom",
              "position_increment_gap" : "0",
              "tokenizer" : "whitespace"
            }
          }
        }
  },
  "mappings": {
    "dynamic" : "strict",
    "date_detection" : false,
    "numeric_detection" : false,
    "properties": {
      "sentences" : {
          "dynamic" : "false",
          "properties" : {
            "text" : {
              "type" : "text",
              "analyzer" : "custom_analyzer",
              "index_prefixes" : {
                "min_chars" : 1,
                "max_chars" : 10
              }
            }
          }
        }
    }
  }
}

```

Add a document:

```auto
PUT test/_doc/Search-Test#1
{
          "sentences" : [
            {
              "text" : "4/30/2021"
            },
            {
              "text" : "RFC 6585 - Additional HTTP Status Codes"
            },
            {
              "text" : "Internet Engineering Task Force (IETF)"
            }
          ]
        }

```

Perform a search:

```auto
GET /test/_search
{
  "query": {
    "match_phrase_prefix": {
      "sentences.text": {
        "query": "Additional HTTP"
      }
    }
  }
}

```

UPD Looks like "index\_prefixes" field in index mappings causes query to stop working. If I remove it, search returns results, but I can't imagine why.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [May 10, 2021, 1:22pm UTC](https://discuss.elastic.co/t/match-phrase-prefix-query-stopped-working-for-multiple-terms-after-7-10-2/272293/2 "2021-05-10T13:22:43Z")

</div>

This looks like an issue then. I opened [Match phrase query stopped working after 7.10.2 · Issue #72885 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/72885)

---

<div class="post-metadata">

### Author: ![AlanWoodward](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alanwoodward/32/41962_2.png) [@AlanWoodward](https://discuss.elastic.co/u/AlanWoodward)
#### Post date: [May 11, 2021, 1:47pm UTC](https://discuss.elastic.co/t/match-phrase-prefix-query-stopped-working-for-multiple-terms-after-7-10-2/272293/3 "2021-05-11T13:47:57Z")

</div>

Hi @Sleepy_Panda, thanks for opening this. It's definitely a bug, and it's to do with how we handle the position increment gap - specifically, we're not correctly preserving the gap value for the prefix accelerator field if it was set on the root analyzer. You should be able to work around this by setting the position increment gap directly on the text field, like so:

```auto
"text" : {
    "type" : "text",
    "analyzer" : "custom_analyzer",
    "position_increment_gap" : 0,
    "index_prefixes" : {
        "min_chars" : 1,
        "max_chars" 10
    }
}

```

Incidentally, have you found that changing the index\_prefixes values from their default settings of {2, 5} has made a difference? Particularly on the lower end, prefix queries with a single character get rewritten to use simple wildcards and should still perform well - eg, "text:a\*" gets rewritten to "text.\_secret\_prefix\_field:(a || a?)" which has a very low expansion cost and uses a lot less disk space. And stored prefixes beyond 5 characters for most english text doesn't gain you a great deal either, at least in my experiments.

- Alan W

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [June 8, 2021, 10:44am UTC](https://discuss.elastic.co/t/match-phrase-prefix-query-stopped-working-for-multiple-terms-after-7-10-2/272293/4 "2021-06-08T10:44:29Z")

</div>

This has been fixe in 7.13.1 and above... see [Search analyzer should default to configured index analyzer over default by romseygeek · Pull Request #73359 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/pull/73359)

---

<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: [July 6, 2021, 10:45am UTC](https://discuss.elastic.co/t/match-phrase-prefix-query-stopped-working-for-multiple-terms-after-7-10-2/272293/5 "2021-07-06T10:45:12Z")

</div>

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