Autocomplete - Return terms instead of whole documents

Hi

I am trying to implement a simple auto completion for query terms.
There are many different approaches but most of them do return documents instead of terms

  • or the authors simply stopped explaining from that point and i am not able to adapt :pensive:

A user is typing in a query - e.g. phil
What i want is to provide a list of term completion suggestions like philipp, philius, philadelphia, ...

I am able to get document matches via (edge)ngrams, phrase_prefix and so on
but i am am stuck at retrieving matching terms (or candidates).

Can someone give me a hint?

Hi Philipp,
if you look at the Definitive Guide for Elasticsearch, there is an extensive section called "Query-Time Search-as-You-Type". Have a look at that.
Benjamin

Thank you for your answer.

I already tried match_phrase_prefix or match_phrase but my problem is how a result looks
and how i need to process it in order to get the completion suggestions (instead of document results).

Or do i have a general misunderstanding?

(btw: I am working with the java-api)

I use the REST API, but the point is (probably) the same:
In addition to the query, you need to define what the query shall return by using the "_source" or "fields" parameter.

But it do not need the whole content of a field. Only some terms/tokens as completion suggestion.

I have documents like this {"title":"...", "description":"...", "content":"..."}
All fields have larger string values but especially the field content contains fulltext content.

For example while typing phil i do not want to suggest the whole title of a document containing e.g. Philadelphia. Just the word Philadelphia.