Is there any significant implementation difference between terms and term query when there is a single term to search?
In a situation where I know the number of terms in advance, is it worth it to implement them separately?
Ie:
if tokens > 1
buildTermsQuery
else
buildTermQuery
Does a terms query with a single term have any penalty?
Based on what I was able to gather from the query profiler, there seems to be a difference as the Terms query uses a MultiTermQueryConstantScoreBlendedWrapper while the Term query uses TermQuery directly. I just wonder if it ultimately matters
"Giving my two cents", I believe that the performance impact of using terms for a single term would be negligible, even though terms requires the term to go through the list processing flow, as per its default operation. What is really worth paying attention to is correctly mapping the field, ensuring that it is suitable for term-level queries, such as term and terms. Proper mapping, such as using keyword fields, is essential for the proper functioning of these queries.
The terms query is the same as the term query, except you can search for multiple values. A document will match if it contains at least one of the terms. To search for documents that contain more than one matching term, use the terms_set query.
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.