# How exactly works "max\_expansions" in match\_phrase\_prefix query?

**URL:** <https://discuss.elastic.co/t/how-exactly-works-max-expansions-in-match-phrase-prefix-query/10815>\
**Category:** Elasticsearch\
**Created:** [February 20, 2013, 11:33am UTC](https://discuss.elastic.co/t/how-exactly-works-max-expansions-in-match-phrase-prefix-query/10815 "2013-02-20T11:33:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JJack\_PL](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@JJack\_PL](https://discuss.elastic.co/u/JJack_PL)\
**Post date:** [February 20, 2013, 11:33am UTC](https://discuss.elastic.co/t/how-exactly-works-max-expansions-in-match-phrase-prefix-query/10815/1 "2013-02-20T11:33:29Z")

</div>

Example from page:

"match\_phrase\_prefix" : {  
"message" : {  
"query" : "this is a test",  
"max\_expansions" : 10  
}  
}

Can you give me some simple examples on this with different max\_expansions numbers for example for query "a" and multi characters query like "test"?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [February 21, 2013, 2:30pm UTC](https://discuss.elastic.co/t/how-exactly-works-max-expansions-in-match-phrase-prefix-query/10815/2 "2013-02-21T14:30:17Z")

</div>

On Wed, 2013-02-20 at 03:33 -0800, JJack\_PL wrote:

> Example from page:  
> "match\_phrase\_prefix" : {  
> "message" : {  
> "query" : "this is a test",  
> "max\_expansions" : 10  
> }  
> }  
> Can you give me some simple examples on this with different max\_expansions numbers for example for query "a" and multi characters query like "test"?

In the example above, ES will examine all terms in the "message" field  
to look for those that begin with the letters "test". It will combine  
all of those terms into a query (eg "test","tester","testing","tests"  
etc), working in alphabetical (lexicographic) order, up to  
max\_expansions.

Set max\_expansions to limit the number of terms that will be collected.  
Eg, if the prefix is "a" you may end up with thousands of terms, which  
is pretty meaningless. Set max\_expansions to (eg) 30 so that the user  
gets some response, but your server is not overwhelmed by too many  
clauses.

clint

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![shgeorge](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@shgeorge](https://discuss.elastic.co/u/shgeorge)\
**Post date:** [June 5, 2014, 6:49am UTC](https://discuss.elastic.co/t/how-exactly-works-max-expansions-in-match-phrase-prefix-query/10815/3 "2014-06-05T06:49:08Z")

</div>

In the above example if there are documents with terms : "test","tester","testing","tests"  
and we are querying for "test" and "max\_expansions" : 2, should it return only first 2 matching docs?

I see that it is returning all the matching docs. Could you please explain?

---

<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, 2017, 1:24am UTC](https://discuss.elastic.co/t/how-exactly-works-max-expansions-in-match-phrase-prefix-query/10815/4 "2017-07-06T01:24:34Z")

</div>


