# Search-as-you-type vs matchPhasePrefix

**URL:** <https://discuss.elastic.co/t/search-as-you-type-vs-matchphaseprefix/369221>\
**Category:** Elasticsearch\
**Created:** [October 22, 2024, 12:42pm UTC](https://discuss.elastic.co/t/search-as-you-type-vs-matchphaseprefix/369221 "2024-10-22T12:42:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ritvij14](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ritvij14/32/138580_2.png) [@ritvij14](https://discuss.elastic.co/u/ritvij14)\
**Post date:** [October 22, 2024, 12:42pm UTC](https://discuss.elastic.co/t/search-as-you-type-vs-matchphaseprefix/369221/1 "2024-10-22T12:42:50Z")

</div>

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:

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

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [October 22, 2024, 5:49pm UTC](https://discuss.elastic.co/t/search-as-you-type-vs-matchphaseprefix/369221/2 "2024-10-22T17:49:56Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/8.15/search-suggesters.html#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](https://mourjo.medium.com/a-detailed-comparison-between-autocompletion-strategies-in-elasticsearch-66cb9e9c62c4), which, although a bit older, provides good context on the topic.
