Match query

A match query is the default query for most full-text search requirements. It is one of the high-level queries that is aware of the analyzer used for the underlying field. Let's get an understanding of what this means under the hood.

For example, when you use the match query on a keyword field, it knows that the underlying field is a keyword field, and hence, the search terms are not analyzed at the time of querying:

GET /amazon_products/_search
{
"query": {
"match": {
"manufacturer.raw": "victory multimedia"
}
}
}

The match query, in this case, behaves just like a term query, which we understand from the previous section. It does not analyze the search term's victory multimedia as the separate terms victory and multimedia. This is because we are querying a keyword field, manufacturer.raw. In fact, in this particular case, the match query gets converted into a term query, such as the following:

GET /amazon_products/_search
{
"query": {
"term": {
"manufacturer.raw": "victory multimedia"
}
}
}

The term query returns the same scores as the match query in this case, as they are both executed against a keyword field.

Let's see what happens if you execute a match query against a text field, which is a real use case for a full-text query:

GET /amazon_products/_search
{
"query": {
"match": {
"manufacturer": "victory multimedia"
}
}
}

When we execute the match query, we expect it to do the following things:

  • Search for the terms victory and multimedia across all documents within the manufacturer field.
  • Find the best matching documents sorted by score in descending order.
  • If both terms appear in the same order, right next to each other in a document, the document should get a higher score than other documents that have both terms but not in the same order, or not next to each other.
  • Include documents that have either victory or multimedia in the results, but give them a lower score.

The match query with default parameters does all of these things to find the best matching documents in order, according to their scores (high to low).

By default, when only search terms are specified, this is how the match query behaves. It is possible to specify additional options for the match query. Let's look at some typical options that you would specify:

  • Operator
  • Minimum should match
  • Fuzziness
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.199.163