diff --git a/explore-analyze/query-filter/languages/querydsl.md b/explore-analyze/query-filter/languages/querydsl.md index 62f7f0ca47..f8372b0505 100644 --- a/explore-analyze/query-filter/languages/querydsl.md +++ b/explore-analyze/query-filter/languages/querydsl.md @@ -7,7 +7,7 @@ mapped_urls: - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html --- -# QueryDSL +# Query DSL $$$filter-context$$$ diff --git a/solutions/search/hybrid-semantic-text.md b/solutions/search/hybrid-semantic-text.md index e6db19a531..839d1d1ead 100644 --- a/solutions/search/hybrid-semantic-text.md +++ b/solutions/search/hybrid-semantic-text.md @@ -102,7 +102,15 @@ POST _tasks//_cancel ## Perform hybrid search [hybrid-search-perform-search] -After reindexing the data into the `semantic-embeddings` index, you can perform hybrid search by using [reciprocal rank fusion (RRF)](elasticsearch://reference/elasticsearch/rest-apis/reciprocal-rank-fusion.md). RRF is a technique that merges the rankings from both semantic and lexical queries, giving more weight to results that rank high in either search. This ensures that the final results are balanced and relevant. +After reindexing the data into the `semantic-embeddings` index, you can perform hybrid search to combine semantic and lexical search results. Choose between [retrievers](retrievers-overview.md) or [{{esql}}](/explore-analyze/query-filter/languages/esql.md) syntax to execute the query. + +::::{tab-set} +:group: query-type + +:::{tab-item} Query DSL +:sync: retrievers + +This example uses [retrievers syntax](retrievers-overview.md) with [reciprocal rank fusion (RRF)](elasticsearch://reference/elasticsearch/rest-apis/reciprocal-rank-fusion.md). RRF is a technique that merges the rankings from both semantic and lexical queries, giving more weight to results that rank high in either search. This ensures that the final results are balanced and relevant. ```console GET semantic-embeddings/_search @@ -141,7 +149,7 @@ GET semantic-embeddings/_search 4. The `semantic_text` field is used to perform the semantic search. -After performing the hybrid search, the query will return the top 10 documents that match both semantic and lexical search criteria. The results include detailed information about each document: +After performing the hybrid search, the query will return the combined top 10 documents for both semantic and lexical search criteria. The results include detailed information about each document. ```console-result { @@ -202,3 +210,30 @@ After performing the hybrid search, the query will return the top 10 documents t } } ``` +::: + +:::{tab-item} ES|QL +:sync: esql + +The ES|QL approach uses a combination of the match operator `:` and the match function `match()` to perform hybrid search. + +```console +POST /_query?format=txt +{ + "query": """ + FROM semantic-embeddings METADATA _score <1> + | WHERE content: "muscle soreness running?" OR match(semantic_text, "How to avoid muscle soreness while running?", { "boost": 0.75 }) <2> <3> + | SORT _score DESC <4> + | LIMIT 1000 + """ +} +``` +1. The `METADATA _score` clause is used to return the score of each document +2. The [match (`:`) operator](elasticsearch://reference/query-languages/esql/esql-functions-operators.md#esql-search-operators) is used on the `content` field for standard keyword matching +3. Semantic search using the `match()` function on the `semantic_text` field with a boost of `0.75` +4. Sorts by descending score and limits to 1000 results +::: +:::: + + + diff --git a/solutions/search/semantic-search/semantic-search-semantic-text.md b/solutions/search/semantic-search/semantic-search-semantic-text.md index a0cf27513e..7a7c811741 100644 --- a/solutions/search/semantic-search/semantic-search-semantic-text.md +++ b/solutions/search/semantic-search/semantic-search-semantic-text.md @@ -101,15 +101,23 @@ POST _tasks//_cancel ## Semantic search [semantic-text-semantic-search] -After the data set has been enriched with the embeddings, you can query the data using semantic search. Provide the `semantic_text` field name and the query text in a `semantic` query type. The {{infer}} endpoint used to generate the embeddings for the `semantic_text` field will be used to process the query text. +After the data has been indexed with the embeddings, you can query the data using semantic search. Choose between [Query DSL](/explore-analyze/query-filter/languages/querydsl.md) or [{{esql}}](/explore-analyze/query-filter/languages/esql.md) syntax to execute the query. -```console +::::{tab-set} +:group: query-type + +:::{tab-item} Query DSL +:sync: dsl + +The Query DSL approach uses the `semantic` query type with the `semantic_text` field: + +```esql GET semantic-embeddings/_search { "query": { "semantic": { "field": "content", <1> - "query": "How to avoid muscle soreness while running?" <2> + "query": "What causes muscle soreness after running?" <2> } } } @@ -117,9 +125,32 @@ GET semantic-embeddings/_search 1. The `semantic_text` field on which you want to perform the search. 2. The query text. +::: + +:::{tab-item} ES|QL +:sync: esql + +The ES|QL approach uses the [match (`:`) operator](elasticsearch://reference/query-languages/esql/esql-functions-operators.md#esql-search-operators), which automatically detects the `semantic_text` field and performs the search on it. The query uses `METADATA _score` to sort by `_score` in descending order. -As a result, you receive the top 10 documents that are closest in meaning to the query from the `semantic-embedding` index. +```console +POST /_query?format=txt +{ + "query": """ + FROM semantic-embeddings METADATA _score <1> + | WHERE content: "How to avoid muscle soreness while running?" <2> + | SORT _score DESC <3> + | LIMIT 1000 <4> + """ +} +``` +1. The `METADATA _score` clause is used to return the score of each document +2. The [match (`:`) operator](elasticsearch://reference/query-languages/esql/esql-functions-operators.md#esql-search-operators) is used on the `content` field for standard keyword matching +3. Sorts by descending score to display the most relevant results first +4. Limits the results to 1000 documents + +::: +:::: ## Further examples and reading [semantic-text-further-examples]