0

Being new to ElasticSearch, need help in my understanding.

What I read about term vs match query is that term query is used for exact match and match query is used when we are searching for a term and want result based on a relevancy score.

But if we already defined a mapping for a field as a keyword, why anyone has to decide upon between term vs match, wouldn't it be always a term query in case mapping is defined as a keyword?

What are the use cases where someone will make a match query on the keyword mapping field?

The same confusion is vice versa.

Vip
  • 1,448
  • 2
  • 17
  • 20

1 Answers1

0

A text field will be analyzed (transformed, split) to generate N tokens, and the keyword itself will become a token with no transformations. At the end, you have N tokens referencing a document.

Then. By doing a match query, you will treat your query as a text as well, by analyzing it before performing the matching (transforming it), and the term will not.

You can create a field with a term mapping, but then perform a match query on top of it (for example if you want to be case insensitive), and you can create a text mapping for a n-gram and perform a term query to match exactly what you're asking for.

mmoreram
  • 687
  • 5
  • 13
  • Sorry, Still not very clear. Could you please elaborate on a case-insensitive example? I believe to define case insensitive search in an efficient way, you would need to define an analyzer (effectively both mapping and query will be analyzed). – Vip Sep 20 '21 at 04:17