Skip to content

Commit cf8b412

Browse files
committed
[DOCS] Add examples for mget, msearch template
1 parent c9e2757 commit cf8b412

14 files changed

+197
-23
lines changed

specification/_doc_ids/table.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,9 @@ search-render-query,https://www.elastic.co/guide/en/elasticsearch/reference/{bra
600600
search-count,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-count.html
601601
search-explain,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-explain.html
602602
search-field-caps,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-field-caps.html
603+
search-knn,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/knn-search-api.html
603604
search-multi-search,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-multi-search.html
604-
search-multi-search,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-multi-search.html
605+
search-multi-search-template,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/multi-search-template.html
605606
search-rank-eval,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-rank-eval.html
606607
search-rank-eval,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-rank-eval.html
607608
search-request-body,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-request-body.html

specification/_global/knn_search/KnnSearchRequest.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,17 @@ import { Query } from './_types/Knn'
3737
*
3838
* The kNN search API supports restricting the search using a filter.
3939
* The search will return the top k documents that also match the filter query.
40+
*
41+
* A kNN search response has the exact same structure as a search API response.
42+
* However, certain sections have a meaning specific to kNN search:
43+
*
44+
* * The document `_score` is determined by the similarity between the query and document vector.
45+
* * The `hits.total` object contains the total number of nearest neighbor candidates considered, which is `num_candidates * num_shards`. The `hits.total.relation` will always be `eq`, indicating an exact value.
4046
* @rest_spec_name knn_search
4147
* @availability stack since=8.0.0 stability=experimental
4248
* @deprecated 8.4.0 The kNN search API has been replaced by the `knn` option in the search API.
4349
* @doc_tag search
50+
* @doc_id search-knn
4451
*/
4552
export interface Request extends RequestBase {
4653
urls: [
@@ -52,49 +59,52 @@ export interface Request extends RequestBase {
5259
path_parts: {
5360
/**
5461
* A comma-separated list of index names to search;
55-
* use `_all` or to perform the operation on all indices
62+
* use `_all` or to perform the operation on all indices.
5663
*/
5764
index: Indices
5865
}
5966
query_parameters: {
6067
/**
61-
* A comma-separated list of specific routing values
68+
* A comma-separated list of specific routing values.
6269
*/
6370
routing?: Routing
6471
}
6572
body: {
6673
/**
6774
* Indicates which source fields are returned for matching documents. These
68-
* fields are returned in the hits._source property of the search response.
75+
* fields are returned in the `hits._source` property of the search response.
76+
* @default_server true
6977
*/
7078
_source?: SourceConfig
7179
/**
7280
* The request returns doc values for field names matching these patterns
73-
* in the hits.fields property of the response. Accepts wildcard (*) patterns.
81+
* in the `hits.fields` property of the response.
82+
* It accepts wildcard (`*`) patterns.
7483
*/
7584
docvalue_fields?: FieldAndFormat[]
7685
/**
77-
* List of stored fields to return as part of a hit. If no fields are specified,
78-
* no stored fields are included in the response. If this field is specified, the _source
79-
* parameter defaults to false. You can pass _source: true to return both source fields
86+
* A list of stored fields to return as part of a hit. If no fields are specified,
87+
* no stored fields are included in the response. If this field is specified, the `_source`
88+
* parameter defaults to `false`. You can pass `_source: true` to return both source fields
8089
* and stored fields in the search response.
8190
*/
8291
stored_fields?: Fields
8392
/**
8493
* The request returns values for field names matching these patterns
85-
* in the hits.fields property of the response. Accepts wildcard (*) patterns.
94+
* in the `hits.fields` property of the response.
95+
* It accepts wildcard (`*`) patterns.
8696
*/
8797
fields?: Fields
8898
/**
89-
* Query to filter the documents that can match. The kNN search will return the top
99+
* A query to filter the documents that can match. The kNN search will return the top
90100
* `k` documents that also match this filter. The value can be a single query or a
91101
* list of queries. If `filter` isn't provided, all documents are allowed to match.
92102
* @availability stack since=8.2.0
93103
* @availability serverless
94104
*/
95105
filter?: QueryContainer | QueryContainer[]
96106
/**
97-
* kNN query to execute
107+
* The kNN query to run.
98108
* @ext_doc_id query-dsl-knn-query
99109
*/
100110
knn: Query

specification/_global/knn_search/KnnSearchResponse.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@ import { ShardStatistics } from '@_types/Stats'
2525

2626
export class Response<TDocument> {
2727
body: {
28-
/** Milliseconds it took Elasticsearch to execute the request. */
28+
/** The milliseconds it took Elasticsearch to run the request. */
2929
took: long
3030
/**
3131
* If true, the request timed out before completion;
3232
* returned results may be partial or empty.
3333
*/
3434
timed_out: boolean
3535
/**
36-
* Contains a count of shards used for the request.
36+
* A count of shards used for the request.
3737
*/
3838
_shards: ShardStatistics
3939
/**
40-
* Contains returned documents and metadata.
40+
* The returned documents and metadata.
4141
*/
4242
hits: HitsMetadata<TDocument>
4343
/**
44-
* Contains field values for the documents. These fields
44+
* The field values for the documents. These fields
4545
* must be specified in the request using the `fields` parameter.
4646
*/
4747
fields?: Dictionary<string, UserDefinedValue>
4848
/**
49-
* Highest returned document score. This value is null for requests
49+
* The highest returned document score. This value is null for requests
5050
* that do not sort by score.
5151
*/
5252
max_score?: double

specification/_global/mget/MultiGetRequest.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,24 @@ import { Operation } from './types'
2828
* Get multiple JSON documents by ID from one or more indices.
2929
* If you specify an index in the request URI, you only need to specify the document IDs in the request body.
3030
* To ensure fast responses, this multi get (mget) API responds with partial results if one or more shards fail.
31+
*
32+
* **Filter source fields**
33+
*
34+
* By default, the `_source` field is returned for every document (if stored).
35+
* Use the `_source` and `_source_include` or `source_exclude` attributes to filter what fields are returned for a particular document.
36+
* You can include the `_source`, `_source_includes`, and `_source_excludes` query parameters in the request URI to specify the defaults to use when there are no per-document instructions.
37+
*
38+
* **Get stored fields**
39+
*
40+
* Use the `stored_fields` attribute to specify the set of stored fields you want to retrieve.
41+
* Any requested fields that are not stored are ignored.
42+
* You can include the `stored_fields` query parameter in the request URI to specify the defaults to use when there are no per-document instructions.
3143
* @rest_spec_name mget
3244
* @availability stack since=1.3.0 stability=stable
3345
* @availability serverless stability=stable visibility=public
3446
* @index_privileges read
3547
* @doc_tag document
48+
* @eoc_id docs-multi-get
3649
*/
3750
export interface Request extends RequestBase {
3851
urls: [

specification/_global/mget/MultiGetResponse.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import { ResponseItem } from './types'
2121

2222
export class Response<TDocument> {
2323
body: {
24+
/**
25+
* The response includes a docs array that contains the documents in the order specified in the request.
26+
* The structure of the returned documents is similar to that returned by the get API.
27+
* If there is a failure getting a particular document, the error is included in place of the document.
28+
*/
2429
docs: ResponseItem<TDocument>[]
2530
}
2631
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
summary: Get documents by ID
2+
# method_request: "GET /my-index-000001/_mget"
3+
description: >
4+
Run `GET /my-index-000001/_mget`.
5+
When you specify an index in the request URI, only the document IDs are required in the request body.
6+
# type: "request"
7+
value: |-
8+
{
9+
"docs": [
10+
{
11+
"_id": "1"
12+
},
13+
{
14+
"_id": "2"
15+
}
16+
]
17+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
summary: Filter source fields
2+
# method_request: "GET /_mget"
3+
description: >
4+
Run `GET /_mget`.
5+
This request sets `_source` to `false` for document 1 to exclude the source entirely.
6+
It retrieves `field3` and `field4` from document 2.
7+
It retrieves the `user` field from document 3 but filters out the `user.location` field.
8+
# type: "request"
9+
value: |-
10+
{
11+
"docs": [
12+
{
13+
"_index": "test",
14+
"_id": "1",
15+
"_source": false
16+
},
17+
{
18+
"_index": "test",
19+
"_id": "2",
20+
"_source": [ "field3", "field4" ]
21+
},
22+
{
23+
"_index": "test",
24+
"_id": "3",
25+
"_source": {
26+
"include": [ "user" ],
27+
"exclude": [ "user.location" ]
28+
}
29+
}
30+
]
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
summary: Get stored fields
2+
# method_request: "GET /_mget"
3+
description: >
4+
Run `GET /_mget`.
5+
This request retrieves `field1` and `field2` from document 1 and `field3` and `field4` from document 2.
6+
# type: "request"
7+
value: |-
8+
{
9+
"docs": [
10+
{
11+
"_index": "test",
12+
"_id": "1",
13+
"stored_fields": [ "field1", "field2" ]
14+
},
15+
{
16+
"_index": "test",
17+
"_id": "2",
18+
"stored_fields": [ "field3", "field4" ]
19+
}
20+
]
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
summary: Document routing
2+
# method_request: "GET /_mget?routing=key1"
3+
description: >
4+
Run `GET /_mget?routing=key1`.
5+
If routing is used during indexing, you need to specify the routing value to retrieve documents.
6+
This request fetches `test/_doc/2` from the shard corresponding to routing key `key1`.
7+
It fetches `test/_doc/1` from the shard corresponding to routing key `key2`.
8+
# type: "request"
9+
value: |-
10+
{
11+
"docs": [
12+
{
13+
"_index": "test",
14+
"_id": "1",
15+
"routing": "key2"
16+
},
17+
{
18+
"_index": "test",
19+
"_id": "2"
20+
}
21+
]
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
summary: 'A successful response when creating an autoscaling policy.'
2+
# description: "",
3+
# type: "response",
4+
# response_code: 200,
5+
value: "{\n \"acknowledged\": true\n}"

specification/_global/msearch_template/MultiSearchTemplateRequest.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,26 @@ import { RequestItem } from './types'
2424

2525
/**
2626
* Run multiple templated searches.
27+
*
28+
* Run multiple templated searches with a single request.
29+
* If you are providing a text file or text input to `curl`, use the `--data-binary` flag instead of `-d` to preserve newlines.
30+
* For example:
31+
*
32+
* ```
33+
* $ cat requests
34+
* { "index": "my-index" }
35+
* { "id": "my-search-template", "params": { "query_string": "hello world", "from": 0, "size": 10 }}
36+
* { "index": "my-other-index" }
37+
* { "id": "my-other-search-template", "params": { "query_type": "match_all" }}
38+
*
39+
* $ curl -H "Content-Type: application/x-ndjson" -XGET localhost:9200/_msearch/template --data-binary "@requests"; echo
40+
* ```
2741
* @rest_spec_name msearch_template
2842
* @availability stack since=5.0.0 stability=stable
2943
* @availability serverless stability=stable visibility=public
3044
* @index_privileges read
3145
* @doc_tag search
46+
* @doc_id search-multi-search-template
3247
* @ext_doc_id search-templates
3348
*/
3449
export interface Request extends RequestBase {
@@ -44,8 +59,8 @@ export interface Request extends RequestBase {
4459
]
4560
path_parts: {
4661
/**
47-
* Comma-separated list of data streams, indices, and aliases to search.
48-
* Supports wildcards (`*`).
62+
* A comma-separated list of data streams, indices, and aliases to search.
63+
* It supports wildcards (`*`).
4964
* To search all data streams and indices, omit this parameter or use `*`.
5065
*/
5166
index?: Indices
@@ -57,12 +72,11 @@ export interface Request extends RequestBase {
5772
*/
5873
ccs_minimize_roundtrips?: boolean
5974
/**
60-
* Maximum number of concurrent searches the API can run.
75+
* The maximum number of concurrent searches the API can run.
6176
*/
6277
max_concurrent_searches?: long
6378
/**
6479
* The type of the search operation.
65-
* Available options: `query_then_fetch`, `dfs_query_then_fetch`.
6680
*/
6781
search_type?: SearchType
6882
/**
@@ -77,6 +91,25 @@ export interface Request extends RequestBase {
7791
*/
7892
typed_keys?: boolean
7993
}
80-
/** @codegen_name search_templates */
94+
/**
95+
* @codegen_name search_templates
96+
* The request body must be newline-delimited JSON (NDJSON) in the following format:
97+
*
98+
* ```
99+
* <header>\n
100+
* <body>\n
101+
* <header>\n
102+
* <body>\n
103+
* ```
104+
*
105+
* Each `<header>` and `<body>` pair represents a search request.
106+
* The `<header>` supports the same parameters as the multi search API's `<header>`.
107+
* The `<body>` supports the same parameters as the search template API's request body.
108+
*
109+
* The `<header>` contains the parameters used to limit or change the search.
110+
* It is required for each search body but can be empty `({})` or a blank line.
111+
*
112+
* The `<body>` contains the parameters for the search.
113+
*/
81114
body: Array<RequestItem>
82115
}

specification/_global/msearch_template/MultiSearchTemplateResponse.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,12 @@
2020
import { MultiSearchResult } from '@global/msearch/types'
2121

2222
export class Response<TDocument> {
23+
/**
24+
* The API returns a 400 status code only if the request itself fails.
25+
* If one or more searches in the request fail, the API returns a 200 status code with an error object for each failed search in the response.
26+
*
27+
* The body contains results for each search, returned in the order submitted.
28+
* Each object uses the same properties as the search API's response.
29+
*/
2330
body: MultiSearchResult<TDocument>
2431
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# summary:
2+
# method_request: GET my-index/_msearch/template
3+
description: Run `GET my-index/_msearch/template` to run multiple templated searches.
4+
# type: "request"
5+
value: |-
6+
{ }
7+
{ "id": "my-search-template", "params": { "query_string": "hello world", "from": 0, "size": 10 }}
8+
{ }
9+
{ "id": "my-other-search-template", "params": { "query_type": "match_all" }}

specification/_global/msearch_template/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class TemplateConfig {
3131
* @server_default false */
3232
explain?: boolean
3333
/**
34-
* ID of the search template to use. If no source is specified,
34+
* The ID of the search template to use. If no `source` is specified,
3535
* this parameter is required.
3636
*/
3737
id?: Id
@@ -47,7 +47,7 @@ export class TemplateConfig {
4747
profile?: boolean
4848
/**
4949
* An inline search template. Supports the same parameters as the search API's
50-
* request body. Also supports Mustache variables. If no id is specified, this
50+
* request body. It also supports Mustache variables. If no `id` is specified, this
5151
* parameter is required.
5252
*/
5353
source?: string

0 commit comments

Comments
 (0)