Skip to content

Commit f8dc0e5

Browse files
charlotte-hoblikKubik42
authored andcommitted
[DOCS]: Update semantic_text documentation (elastic#136482)
1 parent 5268271 commit f8dc0e5

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

docs/reference/query-languages/query-dsl/query-dsl-semantic-query.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@ applies_to:
1313
We don't recommend this legacy query type for _new_ projects. Use the match query (with [QueryDSL](/reference/query-languages/query-dsl/query-dsl-match-query.md) or [ESQL](/reference/query-languages/esql/functions-operators/search-functions.md#esql-match)) instead. The semantic query remains available to support existing implementations.
1414
::::
1515

16-
The `semantic` query type enables you to perform [semantic search](docs-content://solutions/search/semantic-search.md) on data stored in a [`semantic_text`](/reference/elasticsearch/mapping-reference/semantic-text.md) field.
16+
The `semantic` query type enables you to perform [semantic search](docs-content://solutions/search/semantic-search.md) on data stored in a [`semantic_text`](/reference/elasticsearch/mapping-reference/semantic-text.md) field. This query accepts natural-language text and uses the field’s configured inference endpoint to generate a query embedding and match documents.
1717

18+
For an overview of all query options available for `semantic_text` fields, see [Querying `semantic_text` fields](/reference/elasticsearch/mapping-reference/semantic-text.md#querying-semantic-text-fields).
19+
20+
## Inference endpoint selection
21+
22+
The target field of `semantic` query must be mapped as `semantic_text` and associated with an inference endpoint. At query time, the inference endpoint is chosen as follows:
23+
- If `search_inference_id` is defined, the semantic query uses that endpoint to embed the query.
24+
- If no `search_inference_id` is defined, `inference_id` is used for both indexing and search.
25+
- If no endpoint is specified at mapping, `inference_id` defaults to `.elser-2-elasticsearch`.
26+
27+
The underlying vector type (dense or sparse) is determined by the endpoint automatically. No extra query parameters are required.
1828

1929
## Example request [semantic-query-example]
2030

docs/reference/query-languages/query-dsl/query-dsl-sparse-vector-query.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,54 @@ GET my-index/_search
208208
```
209209
% TEST[skip: Requires inference]
210210

211+
## Example query on a `semantic_text` field
212+
213+
You can also run a `sparse_vector` query directly on a [`semantic_text`](/reference/elasticsearch/mapping-reference/semantic-text.md) field. In this case Elasticsearch automatically uses the inference endpoint configured in the field mapping to expand the query into sparse tokens.
214+
215+
First, create an index with a `semantic_text` field:
216+
217+
```console
218+
PUT /my-semantic-sparse-index
219+
{
220+
"mappings": {
221+
"properties": {
222+
"title": { "type": "text" },
223+
"content_semantic": {
224+
"type": "semantic_text",
225+
"inference_id": ".elser-2-elasticsearch"
226+
}
227+
}
228+
}
229+
}
230+
```
231+
232+
Index some example documents:
233+
234+
```console
235+
POST /my-semantic-sparse-index/_bulk
236+
{ "index": { "_index": "my-semantic-sparse-index", "_id": "1" } }
237+
{ "title": "Best surfing spots", "content_semantic": "Hawaii has world-class surfing with warm water and consistent swells." }
238+
{ "index": { "_index": "my-semantic-sparse-index", "_id": "2" } }
239+
{ "title": "City breaks", "content_semantic": "Paris offers museums, cafés, and beautiful architecture." }
240+
{ "index": { "_index": "my-semantic-sparse-index", "_id": "3" } }
241+
{ "title": "Learning to surf", "content_semantic": "Beginners often start on longboards at gentle beach breaks." }
242+
```
243+
244+
Then query with `sparse_vector` against the `semantic_text` field:
245+
246+
```console
247+
GET my-semantic-sparse-index/_search
248+
{
249+
"size": 3,
250+
"query": {
251+
"sparse_vector": {
252+
"field": "content_semantic",
253+
"query": "best places to surf as a beginner"
254+
}
255+
}
256+
}
257+
```
258+
211259

212260
## Example ELSER query with pruning configuration and rescore [sparse-vector-query-with-pruning-config-and-rescore-example]
213261

0 commit comments

Comments
 (0)