Skip to content

Commit 235f647

Browse files
authored
Update ESQL search tutorial (#912)
- Rename file - Incorporate @aznick's feedback: - Expanded **semantic search** coverage: now includes semantic indexing, searching, and hybrid search with examples and explanations. - Moved semantic search from a “bonus” section to a core step (Step 4). - Added notes/tips on relevance scoring with `_score` and sorting. - Reorganized and clarified filter vs search distinctions. - Appended **related blog posts** section at the end.
1 parent 9df8dcd commit 235f647

File tree

6 files changed

+91
-60
lines changed

6 files changed

+91
-60
lines changed

explore-analyze/query-filter/languages/esql-getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,5 +423,5 @@ For more about data processing with {{esql}}, refer to [Data processing with DIS
423423

424424
To learn more about {{esql}}, refer to [{{esql}} reference](elasticsearch://reference/query-languages/esql.md).
425425

426-
Learn more about using {{esql}} for Search use cases in this tutorial: [Search and filter with {{esql}}](/solutions/search/esql-full-text-filter-tutorial.md).
426+
Learn more about using {{esql}} for Search use cases in this tutorial: [Search and filter with {{esql}}](/solutions/search/esql-search-tutorial.md).
427427

explore-analyze/query-filter/languages/esql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ You can use it:
3535
- In your queries to {{es}} APIs, using the [`_query` endpoint](/explore-analyze/query-filter/languages/esql-rest.md) that accepts queries written in {{esql}} syntax.
3636
- Within various {{kib}} tools such as Discover and Dashboards, to explore your data and build powerful visualizations.
3737

38-
Learn more about using {{esql}} for Search use cases in this tutorial: [Search and filter with {{esql}}](/solutions/search/esql-full-text-filter-tutorial.md).
38+
Learn more about using {{esql}} for Search use cases in this tutorial: [Search and filter with {{esql}}](/solutions/search/esql-search-tutorial.md).
3939

4040
## Next steps
4141

solutions/search/api-quickstarts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Use the following quickstarts to get hands-on experience with Elasticsearch APIs
1515
- [Basic full-text search and filtering in Elasticsearch](querydsl-full-text-filter-tutorial.md): Learn about different options for querying data, including full-text search and filtering, using the Query DSL.
1616
- [Analyze eCommerce data with aggregations using Query DSL](/explore-analyze/query-filter/aggregations/tutorial-analyze-ecommerce-data-with-aggregations-using-query-dsl.md): Learn how to analyze data using different types of aggregations, including metrics, buckets, and pipelines.
1717
% - [Getting started with {{esql}}](esql-getting-started.md): Learn how to query and aggregate your data using {{esql}}.
18-
- [Search and filter with {{esql}}](esql-full-text-filter-tutorial.md): Learn how to perform full-text and semantic search in {{esql}}, combined with filtering.
18+
- [Search and filter with {{esql}}](esql-search-tutorial.md): Learn how to perform full-text and semantic search in {{esql}}, combined with filtering.
1919
- [Semantic search](semantic-search/semantic-search-semantic-text.md): Learn how to create embeddings for your data with `semantic_text` and query using the `semantic` query.
2020
- [Hybrid search](hybrid-semantic-text.md): Learn how to combine semantic search using`semantic_text` with full-text search.
2121
- [Bring your own dense vector embeddings](vector/bring-own-vectors.md): Learn how to ingest dense vector embeddings into Elasticsearch.

solutions/search/esql-full-text-filter-tutorial.md renamed to solutions/search/esql-search-tutorial.md

Lines changed: 86 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ navigation_title: "Search and filter with ES|QL"
88
This tutorial presents examples in {{esql}} syntax. Refer to [the Query DSL version](querydsl-full-text-filter-tutorial.md) for the equivalent examples in Query DSL syntax.
99
:::
1010

11-
This is a hands-on introduction to the basics of [full-text search](full-text.md) with Elasticsearch, also known as *lexical search*, and how to filter search results based on exact criteria. In this scenario, we're implementing a search function for a cooking blog. The blog contains recipes with various attributes including textual content, categorical data, and numerical ratings.
11+
This is a hands-on introduction to the basics of full-text search and semantic search, using [{{esql}}](/explore-analyze/query-filter/languages/esql.md).
1212

13-
This tutorial covers lexical search, with a brief [introductory section on semantic search](#bonus-semantic-search-with-esql) at the end.
13+
% TODO For an overview of all the search capabilities in {{esql}}, refer to [Search with {{esql}}](elasticsearch://reference/query-languages/esql/esql-for-search.md).
14+
15+
In this scenario, we're implementing search for a cooking blog. The blog contains recipes with various attributes including textual content, categorical data, and numerical ratings.
1416

1517
## Requirements
1618

@@ -147,10 +149,12 @@ Full-text search involves executing text-based queries across one or more docume
147149
:::{tip}
148150
{{esql}} provides two ways to perform full-text searches:
149151

150-
1. Full match function syntax: `match(field, "search terms")`
151-
1. Compact syntax using the match operator "`:`": `field:"search terms"`
152+
1. Full [match function](elasticsearch://reference/query-languages/esql/esql-functions-operators.md#esql-match) syntax: `match(field, "search terms")`
153+
1. Compact syntax using the [match operator `:`](elasticsearch://reference/query-languages/esql/esql-functions-operators.md#esql-search-operators): `field:"search terms"`
152154

153155
Both are equivalent and can be used interchangeably. The compact syntax is more concise, while the function syntax allows for more configuration options. We'll use the compact syntax in most examples for brevity.
156+
157+
Refer to the [match function](elasticsearch://reference/query-languages/esql/esql-functions-operators.md#esql-match) reference docs for advanced parameters available with the function syntax.
154158
:::
155159

156160
### Basic full-text query
@@ -163,6 +167,10 @@ FROM cooking_blog # Specify the index to search
163167
| LIMIT 1000 # Return up to 1000 results
164168
```
165169

170+
:::{note}
171+
The results ordering isn't by relevance, as we haven't requested the `_score` metadata field. We'll cover relevance scoring in the next section.
172+
:::
173+
166174
By default, like the Query DSL `match` query, {{esql}} uses `OR` logic between terms. This means it will match documents that contain either "fluffy" or "pancakes", or both, in the description field.
167175

168176
:::{tip}
@@ -200,7 +208,67 @@ FROM cooking_blog
200208

201209
This query searches the title field to match at least 2 of the 3 terms: "fluffy", "pancakes", or "breakfast".
202210

203-
## Step 4: Search across multiple fields at once
211+
## Step 4: Semantic search and hybrid search
212+
213+
### Index semantic content
214+
215+
{{es}} allows you to semantically search for documents based on the meaning of the text, rather than just the presence of specific keywords. This is useful when you want to find documents that are conceptually similar to a given query, even if they don't contain the exact search terms.
216+
217+
ES|QL supports semantic search when your mappings include fields of the [`semantic_text`](elasticsearch://reference/elasticsearch/mapping-reference/semantic-text.md) type. This example mapping update adds a new field called `semantic_description` with the type `semantic_text`:
218+
219+
```console
220+
PUT /cooking_blog/_mapping
221+
{
222+
"properties": {
223+
"semantic_description": {
224+
"type": "semantic_text"
225+
}
226+
}
227+
}
228+
```
229+
230+
Next, index a document with content into the new field:
231+
232+
```console
233+
POST /cooking_blog/_doc
234+
{
235+
"title": "Mediterranean Quinoa Bowl",
236+
"semantic_description": "A protein-rich bowl with quinoa, chickpeas, fresh vegetables, and herbs. This nutritious Mediterranean-inspired dish is easy to prepare and perfect for a quick, healthy dinner.",
237+
"author": "Jamie Oliver",
238+
"date": "2023-06-01",
239+
"category": "Main Course",
240+
"tags": ["vegetarian", "healthy", "mediterranean", "quinoa"],
241+
"rating": 4.7
242+
}
243+
```
244+
245+
### Perform semantic search
246+
247+
Once the document has been processed by the underlying model running on the inference endpoint, you can perform semantic searches. Here's an example natural language query against the `semantic_description` field:
248+
249+
```esql
250+
FROM cooking_blog
251+
| WHERE semantic_description:"What are some easy to prepare but nutritious plant-based meals?"
252+
| LIMIT 5
253+
```
254+
255+
:::{tip}
256+
Follow this [tutorial](/solutions/search/semantic-search/semantic-search-semantic-text.md) if you'd like to test out the semantic search workflow against a large dataset.
257+
:::
258+
259+
### Perform hybrid search
260+
261+
You can combine full-text and semantic queries. In this example we combine full-text and semantic search with custom weights:
262+
263+
```esql
264+
FROM cooking_blog METADATA _score
265+
| WHERE match(semantic_description, "easy to prepare vegetarian meals", { "boost": 0.75 })
266+
OR match(tags, "vegetarian", { "boost": 0.25 })
267+
| SORT _score DESC
268+
| LIMIT 5
269+
```
270+
271+
## Step 5: Search across multiple fields at once
204272

205273
When users enter a search query, they often don't know (or care) whether their search terms appear in a specific field. {{esql}} provides ways to search across multiple fields simultaneously:
206274

@@ -225,14 +293,14 @@ FROM cooking_blog METADATA _score # Request _score metadata for relevance-based
225293
```
226294

227295
:::{tip}
228-
When working with relevance scoring in ES|QL, it's important to understand how `_score` works. If you don't include `METADATA _score` in your query, you're only performing filtering operations with no relevance calculation.
296+
When working with relevance scoring in ES|QL, it's important to understand `_score`. If you don't include `METADATA _score` in your query, you won't see relevance scores in your results. This means you won't be able to sort by relevance or filter based on relevance scores.
229297

230298
When you include `METADATA _score`, search functions included in WHERE conditions contribute to the relevance score. Filtering operations (like range conditions and exact matches) don't affect the score.
231299

232-
Remember that including `METADATA _score` doesn't automatically sort your results by relevance. You must explicitly use `SORT _score DESC` or `SORT _score ASC` to order your results by relevance.
300+
If you want the most relevant results first, you must sort by `_score`, by explicitly using `SORT _score DESC` or `SORT _score ASC`.
233301
:::
234302

235-
## Step 5: Filter and find exact matches
303+
## Step 6: Filter and find exact matches
236304

237305
Filtering allows you to narrow down your search results based on exact criteria. Unlike full-text searches, filters are binary (yes/no) and do not affect the relevance score. Filters execute faster than queries because excluded results don't need to be scored.
238306

@@ -271,7 +339,7 @@ FROM cooking_blog
271339

272340
Like the `term` query in Query DSL, this has zero flexibility and is case-sensitive.
273341

274-
## Step 6: Combine multiple search criteria
342+
## Step 7: Combine multiple search criteria
275343

276344
Complex searches often require combining multiple search criteria:
277345

@@ -304,55 +372,18 @@ FROM cooking_blog METADATA _score
304372
305373
```
306374

307-
## Bonus: Semantic search with ES|QL
308-
309-
ES|QL also supports semantic search when your mappings include fields of the [`semantic_text`](elasticsearch://reference/elasticsearch/mapping-reference/semantic-text.md) type. This example mapping update adds a new field called `semantic_description` with the type `semantic_text`:
310-
311-
```console
312-
PUT /cooking_blog/_mapping
313-
{
314-
"properties": {
315-
"semantic_description": {
316-
"type": "semantic_text"
317-
}
318-
}
319-
}
320-
```
321-
322-
Next, index a document with content into the new field:
323-
324-
```console
325-
POST /cooking_blog/_doc
326-
{
327-
"title": "Mediterranean Quinoa Bowl",
328-
"semantic_description": "A protein-rich bowl with quinoa, chickpeas, fresh vegetables, and herbs. This nutritious Mediterranean-inspired dish is easy to prepare and perfect for a quick, healthy dinner.",
329-
"author": "Jamie Oliver",
330-
"date": "2023-06-01",
331-
"category": "Main Course",
332-
"tags": ["vegetarian", "healthy", "mediterranean", "quinoa"],
333-
"rating": 4.7
334-
}
335-
```
336-
337-
Once the document has been processed by the underlying model running on the inference endpoint, you can perform semantic searches. Here's an example natural language query against the `semantic_description` field:
338-
339-
```esql
340-
FROM cooking_blog
341-
| WHERE semantic_description:"What are some easy to prepare but nutritious plant-based meals?"
342-
| LIMIT 5
343-
344-
```
345-
346-
:::{tip}
347-
Follow this [tutorial](/solutions/search/semantic-search/semantic-search-semantic-text.md) if you'd like to test out the semantic search workflow against a large dataset.
348-
:::
349-
350375
## Learn more
351376

377+
### Documentation
378+
352379
This tutorial introduced the basics of search and filtering in {{esql}}. Building a real-world search experience requires understanding many more advanced concepts and techniques. Here are some resources once you're ready to dive deeper:
353380

354-
- [Full-text search](full-text.md): Learn about the core components of full-text search in Elasticsearch.
355-
- [Text analysis](full-text/text-analysis-during-search.md): Understand how text is processed for full-text search.
381+
% TODO [Search with {{esql}}](): Learn about all your options for search use cases with {{esql}}.
356382
- [{{esql}} search functions](elasticsearch://reference/query-languages/esql/esql-functions-operators.md#esql-search-functions): Explore the full list of search functions available in {{esql}}.
357383
- [Semantic search](/solutions/search/semantic-search.md): Understand your various options for semantic search in Elasticsearch.
358-
- [The `semantic_text` workflow](/solutions/search/semantic-search.md#_semantic_text_workflow): Learn how to use the `semantic_text` field type for semantic search. This is the recommended approach for most users looking to perform semantic search in {{es}}, because it abstracts away the complexity of setting up inference endpoints and models.
384+
- [The `semantic_text` workflow](/solutions/search/semantic-search.md#_semantic_text_workflow): Learn how to use the `semantic_text` field type for semantic search. This is the recommended approach for most users looking to perform semantic search in {{es}}, because it abstracts away the complexity of setting up inference endpoints and models.
385+
386+
### Related blog posts
387+
388+
% TODO [[uncomment once blog is live]] - https://www.elastic.co/blog/esql-you-know-for-search-scoring-semantic-search[ES|QL, you know for Search]: Introducing scoring and semantic search
389+
- [Introducing full text filtering in ES|QL](https://www.elastic.co/blog/introducing-full-text-filtering-with-esql): Overview of text filtering capabilities

solutions/search/querydsl-full-text-filter-tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ applies_to:
1010
# Tutorial: Full-text search and filtering with Query DSL [full-text-filter-tutorial]
1111

1212
:::{tip}
13-
This tutorial presents examples in Query DSL syntax. Refer to [the {{esql}} version](esql-full-text-filter-tutorial.md) for the equivalent examples in {{esql}} syntax.
13+
This tutorial presents examples in Query DSL syntax. Refer to [the {{esql}} version](esql-search-tutorial.md) for the equivalent examples in {{esql}} syntax.
1414
:::
1515

1616
This is a hands-on introduction to the basics of [full-text search](full-text.md) with {{es}}, also known as *lexical search*, using the [`_search` API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-search) and [Query DSL](../../explore-analyze/query-filter/languages/querydsl.md). You’ll also learn how to filter data, to narrow down search results based on exact criteria.

solutions/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ toc:
1212
children:
1313
- file: search/elasticsearch-basics-quickstart.md
1414
- file: search/querydsl-full-text-filter-tutorial.md
15-
- file: search/esql-full-text-filter-tutorial.md
15+
- file: search/esql-search-tutorial.md
1616
- file: search/ingest-for-search.md
1717
children:
1818
- file: search/search-pipelines.md

0 commit comments

Comments
 (0)