0PricingLogin
Elasticsearch & Full Text Search Systems · Lesson

Term and Match Queries

Learn to use `term` queries for exact value matching and `match` queries for full-text analysis and relevancy scoring.

Intro to Term & Match Queries

Welcome to the fundamentals of querying data in Elasticsearch! Today, we'll explore two essential query types: term and match.

Understanding their differences is crucial for effective search. We'll learn when to use each to get exactly the results you need, whether it's an exact value or a flexible full-text search.

Indexing Sample Documents

Before we query, let's index some simple documents into an index called products. We'll use these examples throughout the lesson.

Run these curl commands in your terminal (assuming Elasticsearch is running on localhost:9200):

curl -X PUT "localhost:9200/products/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "Laptop Pro X1",
  "category": "Electronics",
  "description": "A powerful and lightweight laptop for professionals.",
  "price": 1200
}'

curl -X PUT "localhost:9200/products/_doc/2?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "Wireless Mouse",
  "category": "Accessories",
  "description": "Ergonomic wireless mouse with long battery life.",
  "price": 25
}'

curl -X PUT "localhost:9200/products/_doc/3?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "Gaming Keyboard",
  "category": "Electronics",
  "description": "Mechanical keyboard for intense gaming sessions.",
  "price": 90
}'

All lessons in this course

  1. Introduction to Query DSL
  2. Term and Match Queries
  3. Combining Queries with Bool
  4. Filtering, Ranges, and Query Context
← Back to Elasticsearch & Full Text Search Systems