# Using search as you type field for prefix queries

**URL:** <https://discuss.elastic.co/t/using-search-as-you-type-field-for-prefix-queries/317432>\
**Category:** Elasticsearch\
**Created:** [October 25, 2022, 5:28pm UTC](https://discuss.elastic.co/t/using-search-as-you-type-field-for-prefix-queries/317432 "2022-10-25T17:28:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![caseydm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caseydm/32/26771_2.png) [@caseydm](https://discuss.elastic.co/u/caseydm)\
**Post date:** [October 25, 2022, 5:28pm UTC](https://discuss.elastic.co/t/using-search-as-you-type-field-for-prefix-queries/317432/1 "2022-10-25T17:28:44Z")

</div>

I indexed some of my data as a "search as you type" field in Kibana. Specifically, in the query below the field `authorships.author.display_name.autocomplete` is indexed this way. From looking at the documentation, indexing data this way improves prefix queries ([source](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-as-you-type.html#prefix-queries)). Specifically, I believe it works around the problem of needing to increase `max_expansions` to a high amount in order to retrieve all results.

However, I noticed it is not working well with one of my `match_phrase_prefix` queries. I am querying a "search as you type" field but needing to increase max\_expansions to get all results. This slows down the query. The query is part of a nested aggregation. Maybe that is why? Specifically, the query is:

```auto
{
  "aggs": {
    "nested_groupby": {
      "nested": {
        "path": "authorships"
      },
      "aggs": {
        "inner": {
          "filter": {
            "match_phrase_prefix": {
              "authorships.author.display_name.autocomplete": {
                "query": "jones",
                "slop": 1,
                "max_expansions": 1000
              }
            }
          },
          "aggs": {
            "groupby": {
              "terms": {
                "field": "authorships.author.id",
                "missing": "unknown",
                "size": 200
              }
            }
          }
        }
      }
    }
  },
  "size": 0,
  "_source": {
    "excludes": [
      "abstract",
      "fulltext"
    ]
  }
}

```

Does indexing a field as "search as you type" only improve prefix queries? Or does it improve match\_phrase\_prefix as well? Is there something I can do to improve this query so I can get all results without max\_expansions?

---

<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:** [November 22, 2022, 5:29pm UTC](https://discuss.elastic.co/t/using-search-as-you-type-field-for-prefix-queries/317432/2 "2022-11-22T17:29:18Z")

</div>

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