# Prefix Queries Using NEST API

**URL:** <https://discuss.elastic.co/t/prefix-queries-using-nest-api/307590>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 19, 2022, 7:48pm UTC](https://discuss.elastic.co/t/prefix-queries-using-nest-api/307590 "2022-06-19T19:48:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xef](https://avatars.discourse-cdn.com/v4/letter/x/898d66/32.png) [@xef](https://discuss.elastic.co/u/xef)\
**Post date:** [June 19, 2022, 7:48pm UTC](https://discuss.elastic.co/t/prefix-queries-using-nest-api/307590/1 "2022-06-19T19:48:44Z")

</div>

Is there any way to analyze the prefix text as the same analyzer used in the indexing.  
For example :

```auto
var searchResponse = await client.SearchAsync<Locality>(s => s.Index($"localities-{country.ToLower()}")
               .Query(q => q
                .Prefix(c => c
                .Name("named_query")
                .Boost(1.1)
                .Field(p => p.Name)
                .Value(locality.ToLower())
                .Rewrite(MultiTermQueryRewrite.TopTerms(10))
                    )

               )
            );

```

We keep having to use the ToLower() function to lowecase everything which is not ideal as the analysis in the index may be different.

---

<div class="post-metadata">

**Author:** ![Mikhail\_Khludnev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikhail_khludnev/32/59591_2.png) [@Mikhail\_Khludnev](https://discuss.elastic.co/u/Mikhail_Khludnev)\
**Post date:** [June 20, 2022, 8:43pm UTC](https://discuss.elastic.co/t/prefix-queries-using-nest-api/307590/2 "2022-06-20T20:43:57Z")

</div>

Giving the note [Term-level queries | Elasticsearch Guide [8.2] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/term-level-queries.html#term-level-queries) It's might be possible with `match_bool_prefix` or via tweaking normalizer for `named_query` if it's a `keyword` field.

---

<div class="post-metadata">

**Author:** ![xef](https://avatars.discourse-cdn.com/v4/letter/x/898d66/32.png) [@xef](https://discuss.elastic.co/u/xef)\
**Post date:** [June 21, 2022, 4:00pm UTC](https://discuss.elastic.co/t/prefix-queries-using-nest-api/307590/3 "2022-06-21T16:00:30Z")

</div>

Hi,  
Thanks for your reply.  
Yes it is possible but we also need to include a filter in the query which none of the available options seem to allow it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 19, 2022, 4:00pm UTC](https://discuss.elastic.co/t/prefix-queries-using-nest-api/307590/4 "2022-07-19T16:00:54Z")

</div>

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