フィルタリング、範囲、クエリコンテキスト
クエリコンテキストとフィルターコンテキストの違いを理解し、範囲フィルターやtermフィルターで結果を効率的に絞り込む方法を身につけます。
「フィルタリング、範囲、クエリコンテキスト」はCoddyKit上の無料Elasticsearch & Full Text Search Systemsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはElasticsearch & Full Text Search Systems学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Elasticsearch & Full Text Search Systemsコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Two Contexts
Every clause in Elasticsearch runs in one of two contexts: query context (How well does this match? produces a score) or filter context (Does this match? yes/no, no score).
Why Filters Are Fast
Filters do not compute relevance scores and their results are cached, so repeated filters are very cheap. Use filters whenever you do not need ranking from that clause.
The bool filter Clause
Inside a bool query, the filter array runs in filter context while must runs in query context.
GET /products/_search
{ "query": { "bool": {
"must": [ { "match": { "name": "laptop" } } ],
"filter": [ { "term": { "in_stock": true } } ]
}}}Range Queries
The range query selects values within bounds using gte, gt, lte, lt. It is commonly placed in filter context.
{ "range": { "price": { "gte": 100, "lte": 500 } } }Date Ranges
Range works on dates too, including date math like now-7d for relative windows.
{ "range": { "created": { "gte": "now-7d/d" } } }terms Filter
The terms query matches any of several exact values, like a SQL IN list.
{ "terms": { "category": [ "books", "music" ] } }exists Filter
The exists query keeps only documents that have a non-null value for a field.
{ "exists": { "field": "discount" } }Combining Many Filters
Stack multiple filters in the filter array; they are ANDed together and all benefit from caching.
"filter": [
{ "term": { "in_stock": true } },
{ "range": { "price": { "lte": 1000 } } }
]must_not for Exclusion
Use must_not inside bool to exclude documents. It also runs in filter context.
"must_not": [ { "term": { "discontinued": true } } ]Sorting Without Scores
When you rely on filters alone, every document scores the same, so add an explicit sort (for example by price or date) to order results.
"sort": [ { "price": "asc" } ]Performance Rule of Thumb
Put the scoring text match in must and push every yes/no condition into filter. This keeps scoring focused and lets caching speed up the rest.
Quick Check
When should a clause go in filter context?
Recap
You learned the query vs filter context distinction, used range, terms, and exists filters inside bool, applied must_not for exclusion, and added explicit sorting when relying on filters.
AI チューターと学ぶ Elasticsearch & Full Text Search Systems — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 12
- レッスン
- 48
よくある質問
「フィルタリング、範囲、クエリコンテキスト」レッスンは無料ですか?
はい。「フィルタリング、範囲、クエリコンテキスト」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Elasticsearch & Full Text Search Systemsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Elasticsearch & Full Text Search Systemsコースには全4レッスンが含まれています。
「フィルタリング、範囲、クエリコンテキスト」で何を学びますか?
クエリコンテキストとフィルターコンテキストの違いを理解し、範囲フィルターやtermフィルターで結果を効率的に絞り込む方法を身につけます。 ブラウザで直接実行するハンズオンコードでElasticsearch & Full Text Search Systemsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Elasticsearch & Full Text Search Systemsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのElasticsearch & Full Text Search Systemsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「フィルタリング、範囲、クエリコンテキスト」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このElasticsearch & Full Text Search Systemsレッスンでコードを書いて実行できますか?
はい。すべてのElasticsearch & Full Text Search Systemsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Query DSL入門
- TermクエリとMatchクエリ
- Boolによるクエリの組み合わせ
- フィルタリング、範囲、クエリコンテキスト