# Safe to use prefix query on analysed field?

**URL:** <https://discuss.elastic.co/t/safe-to-use-prefix-query-on-analysed-field/23430>\
**Category:** Elasticsearch\
**Created:** [April 28, 2015, 7:59am UTC](https://discuss.elastic.co/t/safe-to-use-prefix-query-on-analysed-field/23430 "2015-04-28T07:59:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidbkemp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidbkemp/32/594_2.png) [@davidbkemp](https://discuss.elastic.co/u/davidbkemp)\
**Post date:** [April 28, 2015, 7:59am UTC](https://discuss.elastic.co/t/safe-to-use-prefix-query-on-analysed-field/23430/1 "2015-04-28T07:59:50Z")

</div>

The documentation on prefix queries states: "Matches documents that have fields containing terms with a specified prefix (not analyzed)".

I took this to mean that the mapping for the field had to be not\_analized. However, after some experimentation, I found that it does sort of work on an analysed field, but the query is not analysed. Eg. I found I could use a custom analyser on the field that uses a keyword tokenizer and a lowercase token filter and, so long as I lower case the query string myself, I can use a prefix query to get a case insensitive prefix match.

So I am wondering if this is valid and, if so, am I alone in thinking the documentation is misleading? Perhaps it should state that the query is not analysed and to take care when matching on an analysed field?

- David

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5f278ca2-9c2c-417b-a375-13e56682131e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5f278ca2-9c2c-417b-a375-13e56682131e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 28, 2015, 8:37am UTC](https://discuss.elastic.co/t/safe-to-use-prefix-query-on-analysed-field/23430/2 "2015-04-28T08:37:02Z")

</div>

It means that the text you give to the prefix query is not analyzed.

So if you have in the inverted index

- abc
- def

And you search with prefix AB, it won’t work as abc does not start with AB

Make sense?

--  
David Pilato - Developer | Evangelist

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co/)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 28 avr. 2015 à 09:59, David Kemp [davidbkemp@gmail.com](mailto:davidbkemp@gmail.com) a écrit :
> 
> The documentation on prefix queries states: "Matches documents that have fields containing terms with a specified prefix (not analyzed)".
> 
> I took this to mean that the mapping for the field had to be not\_analized. However, after some experimentation, I found that it does sort of work on an analysed field, but the query is not analysed. Eg. I found I could use a custom analyser on the field that uses a keyword tokenizer and a lowercase token filter and, so long as I lower case the query string myself, I can use a prefix query to get a case insensitive prefix match.
> 
> So I am wondering if this is valid and, if so, am I alone in thinking the documentation is misleading? Perhaps it should state that the query is not analysed and to take care when matching on an analysed field?
> 
> - David
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5f278ca2-9c2c-417b-a375-13e56682131e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5f278ca2-9c2c-417b-a375-13e56682131e%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/632F9B0A-C34F-4CEA-AA13-77D1165962EE%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/632F9B0A-C34F-4CEA-AA13-77D1165962EE%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![davidbkemp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidbkemp/32/594_2.png) [@davidbkemp](https://discuss.elastic.co/u/davidbkemp)\
**Post date:** [April 29, 2015, 7:41am UTC](https://discuss.elastic.co/t/safe-to-use-prefix-query-on-analysed-field/23430/3 "2015-04-29T07:41:43Z")

</div>

Yes, that makes sense.  
I still think the documentation could make that a little more clear.  
Thanks very much anyway!

Cheers,  
David

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/da377604-d6ab-4f45-a821-fd4cbe5bb646%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/da377604-d6ab-4f45-a821-fd4cbe5bb646%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 29, 2015, 8:29am UTC](https://discuss.elastic.co/t/safe-to-use-prefix-query-on-analysed-field/23430/4 "2015-04-29T08:29:23Z")

</div>

Well. If you’d like to enhance the documentation, feel free to send a pull request! 🙂

--  
David Pilato - Developer | Evangelist

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co/)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 29 avr. 2015 à 09:41, David Kemp [davidbkemp@gmail.com](mailto:davidbkemp@gmail.com) a écrit :
> 
> Yes, that makes sense.  
> I still think the documentation could make that a little more clear.  
> Thanks very much anyway!
> 
> Cheers,  
> David
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/da377604-d6ab-4f45-a821-fd4cbe5bb646%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/da377604-d6ab-4f45-a821-fd4cbe5bb646%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/C0C107AD-E648-4462-B15D-80895FA55244%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/C0C107AD-E648-4462-B15D-80895FA55244%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:17am UTC](https://discuss.elastic.co/t/safe-to-use-prefix-query-on-analysed-field/23430/5 "2017-07-06T00:17:11Z")

</div>


