# How max expansion works?

**URL:** <https://discuss.elastic.co/t/how-max-expansion-works/171534>\
**Category:** Elasticsearch\
**Created:** [March 8, 2019, 5:12pm UTC](https://discuss.elastic.co/t/how-max-expansion-works/171534 "2019-03-08T17:12:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![c\_sharper](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@c\_sharper](https://discuss.elastic.co/u/c_sharper)\
**Post date:** [March 8, 2019, 5:12pm UTC](https://discuss.elastic.co/t/how-max-expansion-works/171534/1 "2019-03-08T17:12:17Z")

</div>

Hi, I faced the same problem as discussed here: [How exactly works "max\_expansions" in match\_phrase\_prefix query? - #2 by Clinton\_Gormley](https://discuss.elastic.co/t/how-exactly-works-max-expansions-in-match-phrase-prefix-query/10815/2)  
But this is still not answered.

I'm testing how match\_phrase\_prefix and max expanstion property works in Elasticsearch. Reffering to documentation of max expansion:

> **[Match phrase prefix query | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html)**

> Then it looks at the sorted term dictionary to find the first 50 terms that begin with f, and adds these terms to the phrase query.

So I added 3 documents to my test index:

- trying out Elasticsearch
- trying out Elasticsearch2
- trying out Elasticsearch3

Then when I try to query this with max\_expansion set to 2, I get all documents instead of 2.

```auto
GET /_search
{
    "query": {
        "match_phrase_prefix" : {
            "message" : {
                "query" : "trying out E",
                "max_expansions" : 2
            }
        }
    }
}

```

Result:

```auto
{
      "took": 11,
      "timed_out": false,
      "_shards": {
        "total": 34,
        "successful": 34,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": 3,
        "max_score": 1.7260926,
        "hits": [
          {
            "_source": {
              "message": "trying out Elasticsearch2"
            }
          },
          {
            "_source": {
              "message": "trying out Elasticsearch"
            }
          },
          {
            "_source": {
              "message": "trying out Elasticsearch3"
            }
          }
        ]
      }
}

```

---

<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 5, 2019, 5:12pm UTC](https://discuss.elastic.co/t/how-max-expansion-works/171534/2 "2019-04-05T17:12:20Z")

</div>

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