Description
When querying a context awarecompletion
field it is possible to omit the context
and search for all possible contexts for the suggestions. This has the advantage to be flexible, you don't need to know all possible contexts at query time but it also makes the suggester very slow since the context
of the suggestions are added as a prefix at indexing time. When no context is given, the completion suggester needs to follow all possible context paths and starts the real suggestion query from all the leaves of these paths. It works ok if you have a small number of contexts but degrades quickly. One solution could be to limit the number of context values that you can add in a suggestion at indexing time but that would only count the number of contexts per document not the total number of unique contexts in an index/shard/segments. Another solution would be to limit the number of paths that a query without context can follow and ignores the other if it reaches the limit but this would be weird to return only some results and not all. IMO the best solution would be to require a context on query that targets a context completion field. This would be a breaking change but we already advise in the documentation to add contexts only if you're planning to also query with a context:
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/suggester-context.html#_category_query