Using search as you type field for prefix queries

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). 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:

{
  "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?

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