Match Vs. Term


(Yildiz) #1

Hey there ,

I know that this type of question asked before in some other cases but i really need this to be sure if in my case, Match query or Term query is faster.

I'm gonna ask the question with an example :

The text that i'm gonna search "john-doe-amsterdam-other-field-other-field-...."

In my index ;
person: "john-doe",
city:"amsterdam",
other_field : "other-field",
other_field : "other-field",

I know that amsterdam is a city and can handle extra fields but "john-doe" in my application. So in this case i have two options.
1- Split the text remove amsterdam and other extra fields before search and do a Term query on person.
2- Analyze the text("john-doe-amsterdam-other-field-other-field) while indexing with pattern tokinizer ("-") and do a Match Query.
(The output of analyze will be indexed i think and match query will check a list of string.)

So in this case, i guess text = field will be faster than list = list

Anyway which method would you choose ? Doing string process in web server and then ask Elasticsearch or leave it to ElasticSearch completely ? Does match query run as well as term query in any circumstances?


(Ivan Brusic) #2

If you analyze the text during indexing with a pattern tokenizer, then you
should be able to do a match query as well since each term will be indexed
as a separate token, assuming you do not further alter terms with stemming,
synonyms, etc and the casing matches.

The speed of the actual term and match query should not make a difference
since they both use the same inverted index. The match query will go
through the extra step of analyzing the query term, but I believe the the
performance of this extra step to be negligible.

Precision is a different matter. The term query will be accurate if you
want exact matching for "john-doe".


(Yildiz) #3

Nope there will be no stemming, synonyms or something like that. Actually i want to find combinations of "john-doe" like "john-doe-field1-field2" , "john-doe-amsterdam-field2-field1" .... goes on. I can make an exact search on "john-doe" with splitting and replacing the text but the question is should i do that ?


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.