# Phrase prefix query is not working with pagination

**URL:** <https://discuss.elastic.co/t/phrase-prefix-query-is-not-working-with-pagination/364657>\
**Category:** Elasticsearch\
**Created:** [August 9, 2024, 8:50am UTC](https://discuss.elastic.co/t/phrase-prefix-query-is-not-working-with-pagination/364657 "2024-08-09T08:50:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aryan11](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aryan11/32/122198_2.png) [@Aryan11](https://discuss.elastic.co/u/Aryan11)\
**Post date:** [August 9, 2024, 8:50am UTC](https://discuss.elastic.co/t/phrase-prefix-query-is-not-working-with-pagination/364657/1 "2024-08-09T08:50:46Z")

</div>

The following query does not give any results when the **from** parameter is greater than **50**. The number of hits also reduces as this parameter is gradulaly increased from **0**. This works as expected if the query type is **bool\_prefix**.

All the users have name in the following format: **"test\_n"** , e.g. test\_1, test\_2, test\_3, etc. And search.name, search.email are of type **search\_as\_you\_type**.

```auto
GET /users/_search
{
    "query": {
        "function_score": {
            "query": {
                "bool": {
                    "filter": [
                        {
                            "term": {
                                "status.name": "active"
                            }
                        },
                        {
                            "term": {
                                "organisation._id": "1"
                            }
                        }
                    ],
                    "should": [
                        {
                            "multi_match": {
                                "boost": 1,
                                "query": "test_2",
                                "type": "phrase_prefix",
                                "fields": [
                                    "search.name",
                                    "search.email"
                                ]
                            }
                        }
                    ],
                    "minimum_should_match": 1
                }
            }
        }
    },
    "size": 5,
    "from": 50,
}

```

---

<div class="post-metadata">

**Author:** ![Artem\_Shelkovnikov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/artem_shelkovnikov/32/134322_2.png) [@Artem\_Shelkovnikov](https://discuss.elastic.co/u/Artem_Shelkovnikov)\
**Post date:** [August 9, 2024, 1:08pm UTC](https://discuss.elastic.co/t/phrase-prefix-query-is-not-working-with-pagination/364657/2 "2024-08-09T13:08:31Z")

</div>

From #Elastic Search to #Elasticsearch

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [August 9, 2024, 7:28pm UTC](https://discuss.elastic.co/t/phrase-prefix-query-is-not-working-with-pagination/364657/3 "2024-08-09T19:28:37Z")

</div>

Hi @Aryan11 and welcome to the community.

The issue that you're experiencing is because the `max_expansions` parameter defaults to 50. You can set it at a higher number if you need more results. For example, setting `max_expansions` to 100 will now return a max of 100 results, and thus pagination starting from 50 will work on a document that has that many matching documents:

```auto
GET /test-prefix-query/_search
{
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "should": [
            {
              "multi_match": {
                "boost": 1,
                "query": "test_2",
                "type": "phrase_prefix",
                "max_expansions": 100,
                "fields": [
                  "name"
                ]
              }
            }
          ],
          "minimum_should_match": 1
        }
      }
    }
  },
  "size": 5,
  "from": 0
}

```

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Aryan11](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aryan11/32/122198_2.png) [@Aryan11](https://discuss.elastic.co/u/Aryan11)\
**Post date:** [August 12, 2024, 4:39am UTC](https://discuss.elastic.co/t/phrase-prefix-query-is-not-working-with-pagination/364657/4 "2024-08-12T04:39:09Z")

</div>

Thanks @Kathleen_DeRusso this works!

---

<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:** [September 9, 2024, 4:39am UTC](https://discuss.elastic.co/t/phrase-prefix-query-is-not-working-with-pagination/364657/5 "2024-09-09T04:39:23Z")

</div>

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