Term query vs match query

Could somebody help me understand the difference between a term query and a
match query? I saw the explanation on the elasticsearch site but couldn't
quite follow. Isn't search always trying to match terms?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

2 Likes

The match query analyzes the input string and constructs more basic queries
from that.

The term query matches exact terms.

If you have a document containing "CAT" and search for "cat" the match
query will find it but the term query won't. That is, if you lowercase in
your analysis config which it does by default.

On Mon, Nov 18, 2013 at 8:11 PM, Mohit Anchlia mohitanchlia@gmail.comwrote:

Could somebody help me understand the difference between a term query and
a match query? I saw the explanation on the elasticsearch site but couldn't
quite follow. Isn't search always trying to match terms?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

2 Likes

Thanks that helps! Is analysis mostly based off the lower/upper case? Or
does it also breaks a text into multiple individual terms?

On Mon, Nov 18, 2013 at 5:14 PM, Nikolas Everett nik9000@gmail.com wrote:

The match query analyzes the input string and constructs more basic
queries from that.

The term query matches exact terms.

If you have a document containing "CAT" and search for "cat" the match
query will find it but the term query won't. That is, if you lowercase in
your analysis config which it does by default.

On Mon, Nov 18, 2013 at 8:11 PM, Mohit Anchlia mohitanchlia@gmail.comwrote:

Could somebody help me understand the difference between a term query and
a match query? I saw the explanation on the elasticsearch site but couldn't
quite follow. Isn't search always trying to match terms?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Both. And stemming if your field has that. And stopwords. It uses the configured query analyzer for that field which defaults to the index analyzer for that field which defaults to the "standard" analyzer.

For non strings match will parse strings into that type.

It can do more stuff too but you can read about that on the page.

Sent from my iPhone

On Nov 18, 2013, at 8:20 PM, Mohit Anchlia mohitanchlia@gmail.com wrote:

Thanks that helps! Is analysis mostly based off the lower/upper case? Or does it also breaks a text into multiple individual terms?

On Mon, Nov 18, 2013 at 5:14 PM, Nikolas Everett nik9000@gmail.com wrote:
The match query analyzes the input string and constructs more basic queries from that.

The term query matches exact terms.

If you have a document containing "CAT" and search for "cat" the match query will find it but the term query won't. That is, if you lowercase in your analysis config which it does by default.

On Mon, Nov 18, 2013 at 8:11 PM, Mohit Anchlia mohitanchlia@gmail.com wrote:
Could somebody help me understand the difference between a term query and a match query? I saw the explanation on the elasticsearch site but couldn't quite follow. Isn't search always trying to match terms?

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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

So does that mean term query execute faster since it does not involve analysis?

Yes, term query is going to be a bit faster but for user provided text you really need to analyze it for the queries to work properly. I mostly use term queries for keyword style fields where analysis doesn't make sense. Like if I user is picking from a drop down or ticking a box or something.

4 Likes

Thanks, Nik. That makes sense. I guess match query could be used for full-text search where user might not input the exact keyword, but a variant of the search term such as "Fox", "fox, and "foxes" in the search field.