# Analyze Prefix Query

**URL:** https://discuss.elastic.co/t/analyze-prefix-query/123621
**Category:** Elasticsearch
**Created:** [March 12, 2018, 7:36pm UTC](https://discuss.elastic.co/t/analyze-prefix-query/123621 "2018-03-12T19:36:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![han1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/han1/32/20141_2.png) [@han1](https://discuss.elastic.co/u/han1)
#### Post date: [March 12, 2018, 7:36pm UTC](https://discuss.elastic.co/t/analyze-prefix-query/123621/1 "2018-03-12T19:36:01Z")

</div>

We require assistance in creating the required query in Elasticsearch using the NEST library. We have managed to correctly index the data using a custom analyzer (character filters, Tokenizer and Token filters), but are having difficulty in creating a prefix query that ALSO analyzes the data.

It seems that you cannot use a prefix query if you want the query analyzed. But if you use a Match query, then results are returned if there is a match anywhere in the field as opposed to just the beginning which is why we need the prefix query.

We have indexed our data using a custom analyzer:  
.Custom("lowercase", lc =\> lc.CharFilters("removepunctuation").Tokenizer("keyword").Filters("lowercase"))

we have also mapped this analyzer to the field:  
.Text(s =\> s.Name(c =\> c.Name).Analyzer("lowercase")

However if we enter a prefix query the query is not analyzed. If we use a MatchPhrasePrefix the results that come back include records that contain the prefix ANYWHERE in the field - but we need to only return the results if it STARTS with the query.

Can anyone tell us what we need to do to achieve this?

Many thanks

---

<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: [April 9, 2018, 7:36pm UTC](https://discuss.elastic.co/t/analyze-prefix-query/123621/2 "2018-04-09T19:36:25Z")

</div>

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