Safe to use prefix query on analysed field?

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5f278ca2-9c2c-417b-a375-13e56682131e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

@dadoonet https://twitter.com/dadoonet | @elasticsearchfr https://twitter.com/elasticsearchfr | @scrutmydocs https://twitter.com/scrutmydocs

Le 28 avr. 2015 à 09:59, David Kemp 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5f278ca2-9c2c-417b-a375-13e56682131e%40googlegroups.com.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/632F9B0A-C34F-4CEA-AA13-77D1165962EE%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/da377604-d6ab-4f45-a821-fd4cbe5bb646%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

--
David Pilato - Developer | Evangelist

@dadoonet https://twitter.com/dadoonet | @elasticsearchfr https://twitter.com/elasticsearchfr | @scrutmydocs https://twitter.com/scrutmydocs

Le 29 avr. 2015 à 09:41, David Kemp 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/da377604-d6ab-4f45-a821-fd4cbe5bb646%40googlegroups.com.
For more options, visit 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/C0C107AD-E648-4462-B15D-80895FA55244%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.