# Elasticsearch Features and Practical Usage
🧩 Express "a keyword plus many filters" in a single JSON document. Query DSL and its `bool` query are the de facto standard for search backends, and how you use the filter clause decides your performance.
🏷️ Title: Query DSL (JSON query language)
🔗 URL:
📘 Overview
Query DSL is a JSON-style query language used through the `_search` API. It expresses searching, filtering, and aggregations, with queries built as an abstract syntax tree of interconnected clauses. It is the de facto foundation of search backend implementations.
⚙️ How It Works
Two distinctions are key.
・Clause types: standalone "leaf queries" (`match`, `term`, `range`, and so on) and "compound queries" (`bool`, `dis_max`) that wrap them.
・Context: query context asks "how well does this match?" and computes `_score`. Filter context asks a binary "does this match?", skips scoring, runs faster, and is automatically cached.
The central `bool` query has four clauses: `must` (must match, scored), `should` (optional, boosts score, governed by `minimum_should_match`), `filter` (must match, unscored, cached), and `must_not` (excludes, filter context).
🛠️ Practical Usage
For a job search, put the keyword query in `must` and the refinements in `filter`.
```
{ "query": { "bool": {
"must": [ { "multi_match": {
"query": "backend engineer",
"fields": ["title", "description"] } } ],
"filter": [
{ "term": { "location": "tokyo" } },
{ "terms": { "employment_type": ["fulltime", "contract"] } },
{ "range": { "salary": { "gte": 5000000 } } } ] } } }
```
The keyword should influence the score, so it goes in `must`; location, employment type, and salary need no scoring, so they go in `filter`. Filter clauses get cached, making repeated queries fast.
💡 Use Cases
This pattern fits any search app with "full-text plus many structured filters", such as e-commerce, jobs, or real estate. Splitting conditions between `must` (rank by relevance) and `filter` (plain match/no-match) gives you both relevance ranking and strict narrowing in one request.
⚠️ Caveats
The biggest pitfall is confusing `term` and `match`. `term` matches exactly without analysis, so using it on an analyzed `text` field usually returns zero results. Use `match` for `text`, and `term` for `keyword` and structured fields like status or dates. Always put non-scoring conditions in `filter` to benefit from caching and reduced CPU.
#
Elasticsearch# #
QueryDSL#