AI Hints
Home›Elasticsearch Tutorial›Your First Searches
Elasticsearch · Lesson 24 of 120

The match Query

Full-text search.

⏱ 2 min read▶ Video at 21:56🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

Match is the query you'll use most. It's the full-text search query. It splits your text into words, and finds documents that contain any of them.

  • Most used query
  • Full-text
  • Any of the words

Search the description

A customer types, warm jacket. Match searches the description field for those words. Run it. Results with both words score highest. Results with only one word still match, but score lower.

Dev Tools Consoletext
GET products/_search?filter_path=hits.total.value,hits.hits._score,hits.hits._source.name
{
  "query": { "match": { "description": "warm jacket" } },
  "size": 4
}
Output
{
  "hits": {
    "total": {"value": 18},
    "hits": [
      {
        "_score": 3.2714,
        "_source": {"name": "Storm Rain Jacket"}
      },
      {
        "_score": 3.2714,
        "_source": {"name": "Hooded Down Jacket"}
      },
      {
        "_score": 2.0156,
        "_source": {"name": "Breeze Rain Jacket"}
      },
      {
        "_score": 2.0156,
        "_source": {"name": "Cloudburst Rain Jacket"}
      }
    ]
  }
}
Also uses _load
products

Case and words

Match isn't fussy about case. Searching for TENT, in capitals, still finds tents. Run it. That's because both the documents and your search text are split into lower case words. We'll see exactly how later, in the analysis module.

Dev Tools Consoletext
GET products/_search?filter_path=hits.total.value,hits.hits._source.name
{
  "query": { "match": { "name": "TENT" } },
  "size": 3
}
Output
{
  "hits": {
    "total": {"value": 6},
    "hits": [
      {"_source": {"name": "Basecamp Family Tent"}},
      {"_source": {"name": "Ultralight Solo Tent"}},
      {"_source": {"name": "Basecamp 2-Person Tent"}}
    ]
  }
}
Also uses _load
products

Summary

Match splits your text into words, matches any of them, and ranks documents with more matching words higher. Next, how to require all the words.

Key takeaways
  • match
  • Any word
  • Ranked
Next up: AND or OR — operator and minimum_should_match