Your message field is analyzed by default using the Standard Analyzer:
This means your "test message" will become ["test", "message"].
On the other hand, the prefix query isn't analyzed. Which means "test" will
match but "test " won't, because you have no term that begins with that
string.
One solution for this is to index your message field as not_analyzed. This
will only generate the term "test message" which will match both "test" and
"test " prefixes. However, if you search for the "test" term, it won't
match because you have no such term.
You can have the best of both worlds by indexing the same text multiple
times with multiple settings:
This means your "test message" will become ["test", "message"].
On the other hand, the prefix query isn't analyzed. Which means "test"
will match but "test " won't, because you have no term that begins with
that string.
One solution for this is to index your message field as not_analyzed. This
will only generate the term "test message" which will match both "test" and
"test " prefixes. However, if you search for the "test" term, it won't
match because you have no such term.
This means your "test message" will become ["test", "message"].
On the other hand, the prefix query isn't analyzed. Which means "test"
will match but "test " won't, because you have no term that begins with
that string.
One solution for this is to index your message field as not_analyzed.
This will only generate the term "test message" which will match both
"test" and "test " prefixes. However, if you search for the "test" term, it
won't match because you have no such term.
Why does the query work if given in the request query string then?
I think that isn't a valid query. I've just tried it and if I put "bla" in
there I still get the result back. Basically, it will run a match_all
query. It's like doing this:
I think that isn't a valid query. I've just tried it and if I put "bla" in
there I still get the result back. Basically, it will run a match_all
query. It's like doing this:
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.