The term query response has no document, however if i change to match it gives me the result. However, I have certain statuses that have 2 words ("Action Needed"). I would like to search for the exact term.
Thanks a lot Klof. It indeed works. I have a follow up question, I have another field with the same mapping. And it is a id field numeric values in String. For this field the term query works without the keyword version. Can you please help me understand how it works in this case?
Yes because Numeric datatypes are not analyzed, so if your field is define as an integer or float you will be able to Terms query on exact match.
In your mapping, you could also define the type of the documentStatus field as a keyword, if you know that you will always query by "exact match". And in that case, no need to define another version of the field.
Thanks. I do understand if the field is a number then term and match queries can be interchanged for the same result (may be performance of the query would be different). However, like i said the field is a number stored as a string in ES.
The mapping for the id field is as shown below:
Does your explanation holds true even in this case? That because the field documentID is a number represented as a string, somehow ES understands this is a numeric value and handles it like a number and not a string?
Oh ok, no not really, indeed it's a text but when you query on documentID or documentStatus with the text type, it's the standard analyzer (default tokenizer + lowercase) which is applied, if there's no custom analyzer.
So that said, the values will be indexed like :
Data:
documentID: 14360029
documentStatus: New
Indexed in ES:
documentID: 14360029
documentStatus: new
That's the reason why, your terms query on documentID is working, because after having been analyzed the id is exactly the same.
You could try to understand the logic : "term" : { "documentStatus" : "new"}
instead of "term" : { "documentStatus.keyword" : "New"}
Thanks a ton Klof. That explains a lot. Yes it is default tokenizer and lowercase. And the terms query works with the status too. That was very helpful.
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.