Search-as-you-type vs matchPhasePrefix

Hello ES community!

I am a complete newbie to ES and learning on the go as I build functionalities for our company. I have synced my DB with Cloud firestore and the indices are all sorted out. i have also built a prototype of fetching data from the documents, with pagination and queries.

I want to know how search-as-you-type will help in my particular usecase. I have a page where user can see a list of clients, and if they filter with first name or last name i have used match_phrase_prefix to build a searching functionality where API searches with every character.

But I also got to know there is a search-as-you-type type in ES Search. Would that be more helpful in my use case? We will need searching for longer strings soon.

This is my current snippet for the filter:

{
                      match_phrase_prefix: {
                        firstName: {
                          query: firstName,
                          max_expansions: 50,
                        },
                      },
                    }

Hi @ritvij14

First, it's important to understand what kind of functionality you're looking for. In many cases, a search can be divided into two phases:

  1. Phase 1 - Autocomplete (term suggestion): In this phase, the goal is to provide term suggestions as the user types. This can be achieved using tools like Search as You Type or Completion Suggester, which are ideal for autocompleting and suggesting related terms based on what has been typed so far.
  2. Phase 2 - Search based on the term: The second phase happens when the user selects a term from the suggestion or completes the typing manually. Here, you can create a more sophisticated query to return the most relevant documents based on the search term. At this stage, you can combine different clauses to fine-tune the document scoring and improve the relevance of the results.

If your focus is really on implementing an autocomplete and term suggestion feature, tools like Search as You Type or Completion Suggester are the most appropriate for the first phase. In the second phase, a well-configured query is essential to ensure that the most relevant results are returned.

Lastly, I recommend reading this article, which, although a bit older, provides good context on the topic.