Skip to content

Commit 5c3cf5c

Browse files
authored
[DOCS] Add examples for mget, msearch template APIs (#3615) (#3631)
(cherry picked from commit 9b3c186)
1 parent b990f6b commit 5c3cf5c

34 files changed

+1025
-260
lines changed

output/openapi/elasticsearch-openapi.json

Lines changed: 61 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/openapi/elasticsearch-serverless-openapi.json

Lines changed: 52 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

output/schema/schema.json

Lines changed: 114 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specification/_doc_ids/table.csv

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ logstash-centralized-pipeline-management,https://www.elastic.co/guide/en/logstas
300300
logstash-configuration-file-structure,https://www.elastic.co/guide/en/logstash/{branch}/configuration-file-structure.html
301301
logstash-logstash-settings-file,https://www.elastic.co/guide/en/logstash/{branch}/logstash-settings-file.html
302302
lowercase-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/lowercase-processor.html
303+
mapbox-vector-tile,https://github.com/mapbox/vector-tile-spec/blob/master/README.md
303304
mapping-date-format,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/mapping-date-format.html
304305
mapping-meta-field,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/mapping-meta-field.html
305306
mapping-params,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/mapping-params.html
@@ -504,6 +505,7 @@ script-delete,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/d
504505
script-languages,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/get-script-languages-api.html
505506
script-processor,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/script-processor.html
506507
script-put,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/create-stored-script-api.html
508+
scroll-api,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/scroll-api.html
507509
scroll-search-results,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/paginate-search-results.html#scroll-search-results
508510
search-after,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/paginate-search-results.html#search-after
509511
search-aggregations,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-aggregations.html
@@ -592,8 +594,9 @@ search-render-query,https://www.elastic.co/guide/en/elasticsearch/reference/{bra
592594
search-count,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-count.html
593595
search-explain,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-explain.html
594596
search-field-caps,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-field-caps.html
597+
search-knn,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/knn-search-api.html
595598
search-multi-search,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-multi-search.html
596-
search-multi-search,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-multi-search.html
599+
search-multi-search-template,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/multi-search-template.html
597600
search-rank-eval,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-rank-eval.html
598601
search-rank-eval,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-rank-eval.html
599602
search-request-body,https://www.elastic.co/guide/en/elasticsearch/reference/{branch}/search-request-body.html

specification/_global/field_caps/FieldCapabilitiesRequest.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ import { QueryContainer } from '@_types/query_dsl/abstractions'
3535
* @availability serverless stability=stable visibility=public
3636
* @index_privileges view_index_metadata,read
3737
* @doc_tag search
38+
* @doc_id search-field-caps
3839
*/
3940
export interface Request extends RequestBase {
4041
path_parts: {
4142
/**
42-
* Comma-separated list of data streams, indices, and aliases used to limit the request. Supports wildcards (*). To target all data streams and indices, omit this parameter or use * or _all.
43+
* A comma-separated list of data streams, indices, and aliases used to limit the request. Supports wildcards (*). To target all data streams and indices, omit this parameter or use * or _all.
4344
*/
4445
index?: Indices
4546
}
@@ -52,12 +53,12 @@ export interface Request extends RequestBase {
5253
*/
5354
allow_no_indices?: boolean
5455
/**
55-
* Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as `open,hidden`.
56+
* The type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as `open,hidden`.
5657
* @server_default open
5758
*/
5859
expand_wildcards?: ExpandWildcards
5960
/**
60-
* Comma-separated list of fields to retrieve capabilities for. Wildcard (`*`) expressions are supported.
61+
* A comma-separated list of fields to retrieve capabilities for. Wildcard (`*`) expressions are supported.
6162
*/
6263
fields?: Fields
6364
/**
@@ -71,11 +72,15 @@ export interface Request extends RequestBase {
7172
*/
7273
include_unmapped?: boolean
7374
/**
75+
* A comma-separated list of filters to apply to the response.
7476
* @availability stack since=8.2.0
7577
* @availability serverless
7678
*/
7779
filters?: string
7880
/**
81+
* A comma-separated list of field types to include.
82+
* Any fields that do not match one of these types will be excluded from the results.
83+
* It defaults to empty, meaning that all field types are returned.
7984
* @availability stack since=8.2.0
8085
* @availability serverless
8186
*/
@@ -90,17 +95,21 @@ export interface Request extends RequestBase {
9095
}
9196
body: {
9297
/**
93-
* List of fields to retrieve capabilities for. Wildcard (`*`) expressions are supported.
98+
* A list of fields to retrieve capabilities for. Wildcard (`*`) expressions are supported.
9499
* @availability stack since=8.5.0
95100
* @availability serverless
96101
*/
97102
fields?: Fields
98103
/**
99-
* Allows to filter indices if the provided query rewrites to match_none on every shard.
104+
* Filter indices if the provided query rewrites to `match_none` on every shard.
105+
*
106+
* IMPORTANT: The filtering is done on a best-effort basis, it uses index statistics and mappings to rewrite queries to `match_none` instead of fully running the request.
107+
* For instance a range query over a date field can rewrite to `match_none` if all documents within a shard (including deleted documents) are outside of the provided range.
108+
* However, not all queries can rewrite to `match_none` so this API may return an index even if the provided filter matches no document.
100109
*/
101110
index_filter?: QueryContainer
102111
/**
103-
* Defines ad-hoc runtime fields in the request similar to the way it is done in search requests.
112+
* Define ad-hoc runtime fields in the request similar to the way it is done in search requests.
104113
* These fields exist only as part of the query and take precedence over fields defined with the same name in the index mappings.
105114
* @doc_id runtime-search-request
106115
* @availability stack since=7.12.0

specification/_global/field_caps/FieldCapabilitiesResponse.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import { FieldCapability } from './types'
2929
*/
3030
export class Response {
3131
body: {
32+
/**
33+
* The list of indices where this field has the same type family, or null if all indices have the same type family for the field.
34+
*/
3235
indices: Indices
3336
fields: Dictionary<Field, Dictionary<string, FieldCapability>>
3437
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# summary:
2+
# method_request: "POST my-index-*/_field_caps?fields=rating"
3+
description: >
4+
Run `POST my-index-*/_field_caps?fields=rating` to get field capabilities and filter indices with a query.
5+
Indices that rewrite the provided filter to `match_none` on every shard will be filtered from the response.
6+
# type: "request"
7+
value: |-
8+
{
9+
"index_filter": {
10+
"range": {
11+
"@timestamp": {
12+
"gte": "2018"
13+
}
14+
}
15+
}
16+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
summary: Get two fields
2+
# type: "response"
3+
description: >
4+
A successful response from `GET _field_caps?fields=rating,title`.
5+
The field `rating` is defined as a long in `index1` and `index2` and as a `keyword` in `index3` and `index4`.
6+
The field `rating` is not aggregatable in `index1`.
7+
The field `rating` is not searchable in `index4`.
8+
The field `title` is defined as text in all indices.
9+
# response_code: 200,
10+
value: |-
11+
{
12+
"indices": [ "index1", "index2", "index3", "index4", "index5" ],
13+
"fields": {
14+
"rating": {
15+
"long": {
16+
"metadata_field": false,
17+
"searchable": true,
18+
"aggregatable": false,
19+
"indices": [ "index1", "index2" ],
20+
"non_aggregatable_indices": [ "index1" ]
21+
},
22+
"keyword": {
23+
"metadata_field": false,
24+
"searchable": false,
25+
"aggregatable": true,
26+
"indices": [ "index3", "index4" ],
27+
"non_searchable_indices": [ "index4" ]
28+
}
29+
},
30+
"title": {
31+
"text": {
32+
"metadata_field": false,
33+
"searchable": true,
34+
"aggregatable": false
35+
}
36+
}
37+
}
38+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
summary: Get unmapped fields
2+
# type: "response"
3+
description: >
4+
A successful response from `GET _field_caps?fields=rating,title&include_unmapped`.
5+
The response contains an entry for each field that is present in some indices but not all.
6+
For example, the `rating` and `title` fields are unmapped in `index5`.
7+
# response_code: 200,
8+
value: |-
9+
{
10+
"indices": [ "index1", "index2", "index3", "index4", "index5" ],
11+
"fields": {
12+
"rating": {
13+
"long": {
14+
"metadata_field": false,
15+
"searchable": true,
16+
"aggregatable": false,
17+
"indices": [ "index1", "index2" ],
18+
"non_aggregatable_indices": [ "index1" ]
19+
},
20+
"keyword": {
21+
"metadata_field": false,
22+
"searchable": false,
23+
"aggregatable": true,
24+
"indices": [ "index3", "index4" ],
25+
"non_searchable_indices": [ "index4" ]
26+
}
27+
},
28+
"title": {
29+
"text": {
30+
"metadata_field": false,
31+
"searchable": true,
32+
"aggregatable": false
33+
}
34+
}
35+
}
36+
}

specification/_global/knn_search/KnnSearchRequest.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,58 +37,68 @@ 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
path_parts: {
4754
/**
4855
* A comma-separated list of index names to search;
49-
* use `_all` or to perform the operation on all indices
56+
* use `_all` or to perform the operation on all indices.
5057
*/
5158
index: Indices
5259
}
5360
query_parameters: {
5461
/**
55-
* A comma-separated list of specific routing values
62+
* A comma-separated list of specific routing values.
5663
*/
5764
routing?: Routing
5865
}
5966
body: {
6067
/**
6168
* Indicates which source fields are returned for matching documents. These
62-
* fields are returned in the hits._source property of the search response.
69+
* fields are returned in the `hits._source` property of the search response.
70+
* @server_default true
6371
*/
6472
_source?: SourceConfig
6573
/**
6674
* The request returns doc values for field names matching these patterns
67-
* in the hits.fields property of the response. Accepts wildcard (*) patterns.
75+
* in the `hits.fields` property of the response.
76+
* It accepts wildcard (`*`) patterns.
6877
*/
6978
docvalue_fields?: FieldAndFormat[]
7079
/**
71-
* List of stored fields to return as part of a hit. If no fields are specified,
72-
* no stored fields are included in the response. If this field is specified, the _source
73-
* parameter defaults to false. You can pass _source: true to return both source fields
80+
* A list of stored fields to return as part of a hit. If no fields are specified,
81+
* no stored fields are included in the response. If this field is specified, the `_source`
82+
* parameter defaults to `false`. You can pass `_source: true` to return both source fields
7483
* and stored fields in the search response.
7584
*/
7685
stored_fields?: Fields
7786
/**
7887
* The request returns values for field names matching these patterns
79-
* in the hits.fields property of the response. Accepts wildcard (*) patterns.
88+
* in the `hits.fields` property of the response.
89+
* It accepts wildcard (`*`) patterns.
8090
*/
8191
fields?: Fields
8292
/**
83-
* Query to filter the documents that can match. The kNN search will return the top
93+
* A query to filter the documents that can match. The kNN search will return the top
8494
* `k` documents that also match this filter. The value can be a single query or a
8595
* list of queries. If `filter` isn't provided, all documents are allowed to match.
8696
* @availability stack since=8.2.0
8797
* @availability serverless
8898
*/
8999
filter?: QueryContainer | QueryContainer[]
90100
/**
91-
* kNN query to execute
101+
* The kNN query to run.
92102
* @ext_doc_id query-dsl-knn-query
93103
*/
94104
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+
* @doc_id docs-multi-get
3649
*/
3750
export interface Request extends RequestBase {
3851
path_parts: {

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+
}

0 commit comments

Comments
 (0)