diff --git a/specification/_global/reindex/examples/request/ReindexRequestExample10.yaml b/specification/_global/reindex/examples/request/ReindexRequestExample10.yaml new file mode 100644 index 0000000000..dbeaea2d47 --- /dev/null +++ b/specification/_global/reindex/examples/request/ReindexRequestExample10.yaml @@ -0,0 +1,98 @@ +summary: Reindex with Painless +method_request: POST _reindex +description: > + You can use Painless to reindex daily indices to apply a new template to the existing documents. The script extracts the date from + the index name and creates a new index with `-1` appended. For example, all data from `metricbeat-2016.05.31` will be reindexed + into `metricbeat-2016.05.31-1`. +# type: request +value: "{ + + \ \"source\": { + + \ \"index\": \"metricbeat-*\" + + \ }, + + \ \"dest\": { + + \ \"index\": \"metricbeat\" + + \ }, + + \ \"script\": { + + \ \"lang\": \"painless\", + + \ \"source\": \"ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'\" + + \ } + + }" +alternatives: + - language: Python + code: |- + resp = client.reindex( + source={ + "index": "metricbeat-*" + }, + dest={ + "index": "metricbeat" + }, + script={ + "lang": "painless", + "source": "ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'" + }, + ) + - language: JavaScript + code: |- + const response = await client.reindex({ + source: { + index: "metricbeat-*", + }, + dest: { + index: "metricbeat", + }, + script: { + lang: "painless", + source: + "ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'", + }, + }); + - language: Ruby + code: |- + response = client.reindex( + body: { + "source": { + "index": "metricbeat-*" + }, + "dest": { + "index": "metricbeat" + }, + "script": { + "lang": "painless", + "source": "ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'" + } + } + ) + - language: PHP + code: >- + $resp = $client->reindex([ + "body" => [ + "source" => [ + "index" => "metricbeat-*", + ], + "dest" => [ + "index" => "metricbeat", + ], + "script" => [ + "lang" => "painless", + "source" => "ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'", + ], + ], + ]); + - language: curl + code: + "curl -X POST -H \"Authorization: ApiKey $ELASTIC_API_KEY\" -H \"Content-Type: application/json\" -d + '{\"source\":{\"index\":\"metricbeat-*\"},\"dest\":{\"index\":\"metricbeat\"},\"script\":{\"lang\":\"painless\",\"source\":\"\ + ctx._index = '\"'\"'metricbeat-'\"'\"' + (ctx._index.substring('\"'\"'metricbeat-'\"'\"'.length(), ctx._index.length())) + + '\"'\"'-1'\"'\"'\"}}' \"$ELASTICSEARCH_URL/_reindex\"" diff --git a/specification/_global/reindex/examples/request/ReindexRequestExample11.yaml b/specification/_global/reindex/examples/request/ReindexRequestExample11.yaml new file mode 100644 index 0000000000..d0f57bd8e8 --- /dev/null +++ b/specification/_global/reindex/examples/request/ReindexRequestExample11.yaml @@ -0,0 +1,113 @@ +summary: Reindex a random subset +method_request: POST _reindex +description: > + Run `POST _reindex` to extract a random subset of the source for testing. You might need to adjust the `min_score` value depending + on the relative amount of data extracted from source. +# type: request +value: "{ + + \ \"max_docs\": 10, + + \ \"source\": { + + \ \"index\": \"my-index-000001\", + + \ \"query\": { + + \ \"function_score\" : { + + \ \"random_score\" : {}, + + \ \"min_score\" : 0.9 + + \ } + + \ } + + \ }, + + \ \"dest\": { + + \ \"index\": \"my-new-index-000001\" + + \ } + + }" +alternatives: + - language: Python + code: |- + resp = client.reindex( + max_docs=10, + source={ + "index": "my-index-000001", + "query": { + "function_score": { + "random_score": {}, + "min_score": 0.9 + } + } + }, + dest={ + "index": "my-new-index-000001" + }, + ) + - language: JavaScript + code: |- + const response = await client.reindex({ + max_docs: 10, + source: { + index: "my-index-000001", + query: { + function_score: { + random_score: {}, + min_score: 0.9, + }, + }, + }, + dest: { + index: "my-new-index-000001", + }, + }); + - language: Ruby + code: |- + response = client.reindex( + body: { + "max_docs": 10, + "source": { + "index": "my-index-000001", + "query": { + "function_score": { + "random_score": {}, + "min_score": 0.9 + } + } + }, + "dest": { + "index": "my-new-index-000001" + } + } + ) + - language: PHP + code: |- + $resp = $client->reindex([ + "body" => [ + "max_docs" => 10, + "source" => [ + "index" => "my-index-000001", + "query" => [ + "function_score" => [ + "random_score" => new ArrayObject([]), + "min_score" => 0.9, + ], + ], + ], + "dest" => [ + "index" => "my-new-index-000001", + ], + ], + ]); + - language: curl + code: + "curl -X POST -H \"Authorization: ApiKey $ELASTIC_API_KEY\" -H \"Content-Type: application/json\" -d + '{\"max_docs\":10,\"source\":{\"index\":\"my-index-000001\",\"query\":{\"function_score\":{\"random_score\":{},\"min_score\":\ + 0.9}}},\"dest\":{\"index\":\"my-new-index-000001\"}}' \"$ELASTICSEARCH_URL/_reindex\"" diff --git a/specification/_global/reindex/examples/request/ReindexRequestExample12.yaml b/specification/_global/reindex/examples/request/ReindexRequestExample12.yaml new file mode 100644 index 0000000000..66e980472b --- /dev/null +++ b/specification/_global/reindex/examples/request/ReindexRequestExample12.yaml @@ -0,0 +1,102 @@ +summary: Reindex modified documents +method_request: POST _reindex +description: > + Run `POST _reindex` to modify documents during reindexing. This example bumps the version of the source document. +# type: request +value: "{ + + \ \"source\": { + + \ \"index\": \"my-index-000001\" + + \ }, + + \ \"dest\": { + + \ \"index\": \"my-new-index-000001\", + + \ \"version_type\": \"external\" + + \ }, + + \ \"script\": { + + \ \"source\": \"if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}\", + + \ \"lang\": \"painless\" + + \ } + + }" +alternatives: + - language: Python + code: |- + resp = client.reindex( + source={ + "index": "my-index-000001" + }, + dest={ + "index": "my-new-index-000001", + "version_type": "external" + }, + script={ + "source": "if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}", + "lang": "painless" + }, + ) + - language: JavaScript + code: |- + const response = await client.reindex({ + source: { + index: "my-index-000001", + }, + dest: { + index: "my-new-index-000001", + version_type: "external", + }, + script: { + source: + "if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}", + lang: "painless", + }, + }); + - language: Ruby + code: |- + response = client.reindex( + body: { + "source": { + "index": "my-index-000001" + }, + "dest": { + "index": "my-new-index-000001", + "version_type": "external" + }, + "script": { + "source": "if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}", + "lang": "painless" + } + } + ) + - language: PHP + code: |- + $resp = $client->reindex([ + "body" => [ + "source" => [ + "index" => "my-index-000001", + ], + "dest" => [ + "index" => "my-new-index-000001", + "version_type" => "external", + ], + "script" => [ + "source" => "if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}", + "lang" => "painless", + ], + ], + ]); + - language: curl + code: + "curl -X POST -H \"Authorization: ApiKey $ELASTIC_API_KEY\" -H \"Content-Type: application/json\" -d + '{\"source\":{\"index\":\"my-index-000001\"},\"dest\":{\"index\":\"my-new-index-000001\",\"version_type\":\"external\"},\"scr\ + ipt\":{\"source\":\"if (ctx._source.foo == '\"'\"'bar'\"'\"') {ctx._version++; + ctx._source.remove('\"'\"'foo'\"'\"')}\",\"lang\":\"painless\"}}' \"$ELASTICSEARCH_URL/_reindex\"" diff --git a/specification/_global/reindex/examples/request/ReindexRequestExample13.yaml b/specification/_global/reindex/examples/request/ReindexRequestExample13.yaml new file mode 100644 index 0000000000..d0bd227d8d --- /dev/null +++ b/specification/_global/reindex/examples/request/ReindexRequestExample13.yaml @@ -0,0 +1,131 @@ +summary: Reindex from remote on Elastic Cloud +method_request: POST _reindex +description: > + When using Elastic Cloud, you can run `POST _reindex` and authenticate against a remote cluster with an API key. +# type: request +value: "{ + + \ \"source\": { + + \ \"remote\": { + + \ \"host\": \"http://otherhost:9200\", + + \ \"username\": \"user\", + + \ \"password\": \"pass\" + + \ }, + + \ \"index\": \"my-index-000001\", + + \ \"query\": { + + \ \"match\": { + + \ \"test\": \"data\" + + \ } + + \ } + + \ }, + + \ \"dest\": { + + \ \"index\": \"my-new-index-000001\" + + \ } + + }" +alternatives: + - language: Python + code: |- + resp = client.reindex( + source={ + "remote": { + "host": "http://otherhost:9200", + "username": "user", + "password": "pass" + }, + "index": "my-index-000001", + "query": { + "match": { + "test": "data" + } + } + }, + dest={ + "index": "my-new-index-000001" + }, + ) + - language: JavaScript + code: |- + const response = await client.reindex({ + source: { + remote: { + host: "http://otherhost:9200", + username: "user", + password: "pass", + }, + index: "my-index-000001", + query: { + match: { + test: "data", + }, + }, + }, + dest: { + index: "my-new-index-000001", + }, + }); + - language: Ruby + code: |- + response = client.reindex( + body: { + "source": { + "remote": { + "host": "http://otherhost:9200", + "username": "user", + "password": "pass" + }, + "index": "my-index-000001", + "query": { + "match": { + "test": "data" + } + } + }, + "dest": { + "index": "my-new-index-000001" + } + } + ) + - language: PHP + code: |- + $resp = $client->reindex([ + "body" => [ + "source" => [ + "remote" => [ + "host" => "http://otherhost:9200", + "username" => "user", + "password" => "pass", + ], + "index" => "my-index-000001", + "query" => [ + "match" => [ + "test" => "data", + ], + ], + ], + "dest" => [ + "index" => "my-new-index-000001", + ], + ], + ]); + - language: curl + code: + "curl -X POST -H \"Authorization: ApiKey $ELASTIC_API_KEY\" -H \"Content-Type: application/json\" -d + '{\"source\":{\"remote\":{\"host\":\"http://otherhost:9200\",\"username\":\"user\",\"password\":\"pass\"},\"index\":\"my-inde\ + x-000001\",\"query\":{\"match\":{\"test\":\"data\"}}},\"dest\":{\"index\":\"my-new-index-000001\"}}' + \"$ELASTICSEARCH_URL/_reindex\"" diff --git a/specification/_global/reindex/examples/request/ReindexRequestExample2.yaml b/specification/_global/reindex/examples/request/ReindexRequestExample2.yaml new file mode 100644 index 0000000000..4287b24477 --- /dev/null +++ b/specification/_global/reindex/examples/request/ReindexRequestExample2.yaml @@ -0,0 +1,84 @@ +summary: Manual slicing +method_request: POST _reindex +description: > + Run `POST _reindex` to slice a reindex request manually. Provide a slice ID and total number of slices to each request. +# type: request +value: |- + { + "source": { + "index": "my-index-000001", + "slice": { + "id": 0, + "max": 2 + } + }, + "dest": { + "index": "my-new-index-000001" + } + } +alternatives: + - language: Python + code: |- + resp = client.reindex( + source={ + "index": "my-index-000001", + "slice": { + "id": 0, + "max": 2 + } + }, + dest={ + "index": "my-new-index-000001" + }, + ) + - language: JavaScript + code: |- + const response = await client.reindex({ + source: { + index: "my-index-000001", + slice: { + id: 0, + max: 2, + }, + }, + dest: { + index: "my-new-index-000001", + }, + }); + - language: Ruby + code: |- + response = client.reindex( + body: { + "source": { + "index": "my-index-000001", + "slice": { + "id": 0, + "max": 2 + } + }, + "dest": { + "index": "my-new-index-000001" + } + } + ) + - language: PHP + code: |- + $resp = $client->reindex([ + "body" => [ + "source" => [ + "index" => "my-index-000001", + "slice" => [ + "id" => 0, + "max" => 2, + ], + ], + "dest" => [ + "index" => "my-new-index-000001", + ], + ], + ]); + - language: curl + code: + 'curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d + ''{"source":{"index":"my-index-000001","slice":{"id":0,"max":2}},"dest":{"index":"my-new-index-000001"}}'' + "$ELASTICSEARCH_URL/_reindex"' diff --git a/specification/_global/reindex/examples/request/ReindexRequestExample3.yaml b/specification/_global/reindex/examples/request/ReindexRequestExample3.yaml new file mode 100644 index 0000000000..9d7d697f53 --- /dev/null +++ b/specification/_global/reindex/examples/request/ReindexRequestExample3.yaml @@ -0,0 +1,79 @@ +summary: Automatic slicing +method_request: POST _reindex?slices=5&refresh +description: > + Run `POST _reindex?slices=5&refresh` to automatically parallelize using sliced scroll to slice on `_id`. The `slices` parameter + specifies the number of slices to use. +# type: request +value: "{ + + \ \"source\": { + + \ \"index\": \"my-index-000001\" + + \ }, + + \ \"dest\": { + + \ \"index\": \"my-new-index-000001\" + + \ } + + }" +alternatives: + - language: Python + code: |- + resp = client.reindex( + slices="5", + refresh=True, + source={ + "index": "my-index-000001" + }, + dest={ + "index": "my-new-index-000001" + }, + ) + - language: JavaScript + code: |- + const response = await client.reindex({ + slices: 5, + refresh: "true", + source: { + index: "my-index-000001", + }, + dest: { + index: "my-new-index-000001", + }, + }); + - language: Ruby + code: |- + response = client.reindex( + slices: "5", + refresh: "true", + body: { + "source": { + "index": "my-index-000001" + }, + "dest": { + "index": "my-new-index-000001" + } + } + ) + - language: PHP + code: |- + $resp = $client->reindex([ + "slices" => "5", + "refresh" => "true", + "body" => [ + "source" => [ + "index" => "my-index-000001", + ], + "dest" => [ + "index" => "my-new-index-000001", + ], + ], + ]); + - language: curl + code: + 'curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d + ''{"source":{"index":"my-index-000001"},"dest":{"index":"my-new-index-000001"}}'' + "$ELASTICSEARCH_URL/_reindex?slices=5&refresh"' diff --git a/specification/_global/reindex/examples/request/ReindexRequestExample4.yaml b/specification/_global/reindex/examples/request/ReindexRequestExample4.yaml new file mode 100644 index 0000000000..cf9ac7468e --- /dev/null +++ b/specification/_global/reindex/examples/request/ReindexRequestExample4.yaml @@ -0,0 +1,108 @@ +summary: Routing +method_request: POST _reindex +description: > + By default if reindex sees a document with routing then the routing is preserved unless it's changed by the script. You can set + `routing` on the `dest` request to change this behavior. In this example, run `POST _reindex` to copy all documents from the + `source` with the company name `cat` into the `dest` with routing set to `cat`. +# type: request +value: "{ + + \ \"source\": { + + \ \"index\": \"source\", + + \ \"query\": { + + \ \"match\": { + + \ \"company\": \"cat\" + + \ } + + \ } + + \ }, + + \ \"dest\": { + + \ \"index\": \"dest\", + + \ \"routing\": \"=cat\" + + \ } + + }" +alternatives: + - language: Python + code: |- + resp = client.reindex( + source={ + "index": "source", + "query": { + "match": { + "company": "cat" + } + } + }, + dest={ + "index": "dest", + "routing": "=cat" + }, + ) + - language: JavaScript + code: |- + const response = await client.reindex({ + source: { + index: "source", + query: { + match: { + company: "cat", + }, + }, + }, + dest: { + index: "dest", + routing: "=cat", + }, + }); + - language: Ruby + code: |- + response = client.reindex( + body: { + "source": { + "index": "source", + "query": { + "match": { + "company": "cat" + } + } + }, + "dest": { + "index": "dest", + "routing": "=cat" + } + } + ) + - language: PHP + code: |- + $resp = $client->reindex([ + "body" => [ + "source" => [ + "index" => "source", + "query" => [ + "match" => [ + "company" => "cat", + ], + ], + ], + "dest" => [ + "index" => "dest", + "routing" => "=cat", + ], + ], + ]); + - language: curl + code: + "curl -X POST -H \"Authorization: ApiKey $ELASTIC_API_KEY\" -H \"Content-Type: application/json\" -d + '{\"source\":{\"index\":\"source\",\"query\":{\"match\":{\"company\":\"cat\"}}},\"dest\":{\"index\":\"dest\",\"routing\":\"=c\ + at\"}}' \"$ELASTICSEARCH_URL/_reindex\"" diff --git a/specification/_global/reindex/examples/request/ReindexRequestExample5.yaml b/specification/_global/reindex/examples/request/ReindexRequestExample5.yaml new file mode 100644 index 0000000000..4bf87ee51f --- /dev/null +++ b/specification/_global/reindex/examples/request/ReindexRequestExample5.yaml @@ -0,0 +1,75 @@ +summary: Ingest pipelines +method_request: POST _reindex +description: Run `POST _reindex` and use the ingest pipelines feature. +# type: request +value: "{ + + \ \"source\": { + + \ \"index\": \"source\" + + \ }, + + \ \"dest\": { + + \ \"index\": \"dest\", + + \ \"pipeline\": \"some_ingest_pipeline\" + + \ } + + }" +alternatives: + - language: Python + code: |- + resp = client.reindex( + source={ + "index": "source" + }, + dest={ + "index": "dest", + "pipeline": "some_ingest_pipeline" + }, + ) + - language: JavaScript + code: |- + const response = await client.reindex({ + source: { + index: "source", + }, + dest: { + index: "dest", + pipeline: "some_ingest_pipeline", + }, + }); + - language: Ruby + code: |- + response = client.reindex( + body: { + "source": { + "index": "source" + }, + "dest": { + "index": "dest", + "pipeline": "some_ingest_pipeline" + } + } + ) + - language: PHP + code: |- + $resp = $client->reindex([ + "body" => [ + "source" => [ + "index" => "source", + ], + "dest" => [ + "index" => "dest", + "pipeline" => "some_ingest_pipeline", + ], + ], + ]); + - language: curl + code: + 'curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d + ''{"source":{"index":"source"},"dest":{"index":"dest","pipeline":"some_ingest_pipeline"}}'' + "$ELASTICSEARCH_URL/_reindex"' diff --git a/specification/_global/reindex/examples/request/ReindexRequestExample6.yaml b/specification/_global/reindex/examples/request/ReindexRequestExample6.yaml new file mode 100644 index 0000000000..bffcabbf6b --- /dev/null +++ b/specification/_global/reindex/examples/request/ReindexRequestExample6.yaml @@ -0,0 +1,101 @@ +summary: Reindex with a query +method_request: POST _reindex +description: > + Run `POST _reindex` and add a query to the `source` to limit the documents to reindex. For example, this request copies documents + into `my-new-index-000001` only if they have a `user.id` of `kimchy`. +# type: request +value: "{ + + \ \"source\": { + + \ \"index\": \"my-index-000001\", + + \ \"query\": { + + \ \"term\": { + + \ \"user.id\": \"kimchy\" + + \ } + + \ } + + \ }, + + \ \"dest\": { + + \ \"index\": \"my-new-index-000001\" + + \ } + + }" +alternatives: + - language: Python + code: |- + resp = client.reindex( + source={ + "index": "my-index-000001", + "query": { + "term": { + "user.id": "kimchy" + } + } + }, + dest={ + "index": "my-new-index-000001" + }, + ) + - language: JavaScript + code: |- + const response = await client.reindex({ + source: { + index: "my-index-000001", + query: { + term: { + "user.id": "kimchy", + }, + }, + }, + dest: { + index: "my-new-index-000001", + }, + }); + - language: Ruby + code: |- + response = client.reindex( + body: { + "source": { + "index": "my-index-000001", + "query": { + "term": { + "user.id": "kimchy" + } + } + }, + "dest": { + "index": "my-new-index-000001" + } + } + ) + - language: PHP + code: |- + $resp = $client->reindex([ + "body" => [ + "source" => [ + "index" => "my-index-000001", + "query" => [ + "term" => [ + "user.id" => "kimchy", + ], + ], + ], + "dest" => [ + "index" => "my-new-index-000001", + ], + ], + ]); + - language: curl + code: + "curl -X POST -H \"Authorization: ApiKey $ELASTIC_API_KEY\" -H \"Content-Type: application/json\" -d + '{\"source\":{\"index\":\"my-index-000001\",\"query\":{\"term\":{\"user.id\":\"kimchy\"}}},\"dest\":{\"index\":\"my-new-index\ + -000001\"}}' \"$ELASTICSEARCH_URL/_reindex\"" diff --git a/specification/_global/reindex/examples/request/ReindexRequestExample7.yaml b/specification/_global/reindex/examples/request/ReindexRequestExample7.yaml new file mode 100644 index 0000000000..bf5afbe09d --- /dev/null +++ b/specification/_global/reindex/examples/request/ReindexRequestExample7.yaml @@ -0,0 +1,77 @@ +summary: Reindex with max_docs +method_request: POST _reindex +description: > + You can limit the number of processed documents by setting `max_docs`. For example, run `POST _reindex` to copy a single document + from `my-index-000001` to `my-new-index-000001`. +# type: request +value: "{ + + \ \"max_docs\": 1, + + \ \"source\": { + + \ \"index\": \"my-index-000001\" + + \ }, + + \ \"dest\": { + + \ \"index\": \"my-new-index-000001\" + + \ } + + }" +alternatives: + - language: Python + code: |- + resp = client.reindex( + max_docs=1, + source={ + "index": "my-index-000001" + }, + dest={ + "index": "my-new-index-000001" + }, + ) + - language: JavaScript + code: |- + const response = await client.reindex({ + max_docs: 1, + source: { + index: "my-index-000001", + }, + dest: { + index: "my-new-index-000001", + }, + }); + - language: Ruby + code: |- + response = client.reindex( + body: { + "max_docs": 1, + "source": { + "index": "my-index-000001" + }, + "dest": { + "index": "my-new-index-000001" + } + } + ) + - language: PHP + code: |- + $resp = $client->reindex([ + "body" => [ + "max_docs" => 1, + "source" => [ + "index" => "my-index-000001", + ], + "dest" => [ + "index" => "my-new-index-000001", + ], + ], + ]); + - language: curl + code: + 'curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d + ''{"max_docs":1,"source":{"index":"my-index-000001"},"dest":{"index":"my-new-index-000001"}}'' + "$ELASTICSEARCH_URL/_reindex"' diff --git a/specification/_global/reindex/examples/request/ReindexRequestExample8.yaml b/specification/_global/reindex/examples/request/ReindexRequestExample8.yaml new file mode 100644 index 0000000000..549eb679e0 --- /dev/null +++ b/specification/_global/reindex/examples/request/ReindexRequestExample8.yaml @@ -0,0 +1,86 @@ +summary: Reindex selected fields +method_request: POST _reindex +description: > + You can use source filtering to reindex a subset of the fields in the original documents. For example, run `POST _reindex` the + reindex only the `user.id` and `_doc` fields of each document. +# type: request +value: "{ + + \ \"source\": { + + \ \"index\": \"my-index-000001\", + + \ \"_source\": [\"user.id\", \"_doc\"] + + \ }, + + \ \"dest\": { + + \ \"index\": \"my-new-index-000001\" + + \ } + + }" +alternatives: + - language: Python + code: |- + resp = client.reindex( + source={ + "index": "my-index-000001", + "_source": [ + "user.id", + "_doc" + ] + }, + dest={ + "index": "my-new-index-000001" + }, + ) + - language: JavaScript + code: |- + const response = await client.reindex({ + source: { + index: "my-index-000001", + _source: ["user.id", "_doc"], + }, + dest: { + index: "my-new-index-000001", + }, + }); + - language: Ruby + code: |- + response = client.reindex( + body: { + "source": { + "index": "my-index-000001", + "_source": [ + "user.id", + "_doc" + ] + }, + "dest": { + "index": "my-new-index-000001" + } + } + ) + - language: PHP + code: |- + $resp = $client->reindex([ + "body" => [ + "source" => [ + "index" => "my-index-000001", + "_source" => array( + "user.id", + "_doc", + ), + ], + "dest" => [ + "index" => "my-new-index-000001", + ], + ], + ]); + - language: curl + code: + 'curl -X POST -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d + ''{"source":{"index":"my-index-000001","_source":["user.id","_doc"]},"dest":{"index":"my-new-index-000001"}}'' + "$ELASTICSEARCH_URL/_reindex"' diff --git a/specification/_global/reindex/examples/request/ReindexRequestExample9.yaml b/specification/_global/reindex/examples/request/ReindexRequestExample9.yaml new file mode 100644 index 0000000000..a45b9f8dfc --- /dev/null +++ b/specification/_global/reindex/examples/request/ReindexRequestExample9.yaml @@ -0,0 +1,89 @@ +summary: Reindex new field names +method_request: POST _reindex +description: > + A reindex operation can build a copy of an index with renamed fields. If your index has documents with `text` and `flag` fields, + you can change the latter field name to `tag` during the reindex. +# type: request +value: "{ + + \ \"source\": { + + \ \"index\": \"my-index-000001\" + + \ }, + + \ \"dest\": { + + \ \"index\": \"my-new-index-000001\" + + \ }, + + \ \"script\": { + + \ \"source\": \"ctx._source.tag = ctx._source.remove(\\\"flag\\\")\" + + \ } + + }" +alternatives: + - language: Python + code: |- + resp = client.reindex( + source={ + "index": "my-index-000001" + }, + dest={ + "index": "my-new-index-000001" + }, + script={ + "source": "ctx._source.tag = ctx._source.remove(\"flag\")" + }, + ) + - language: JavaScript + code: |- + const response = await client.reindex({ + source: { + index: "my-index-000001", + }, + dest: { + index: "my-new-index-000001", + }, + script: { + source: 'ctx._source.tag = ctx._source.remove("flag")', + }, + }); + - language: Ruby + code: |- + response = client.reindex( + body: { + "source": { + "index": "my-index-000001" + }, + "dest": { + "index": "my-new-index-000001" + }, + "script": { + "source": "ctx._source.tag = ctx._source.remove(\"flag\")" + } + } + ) + - language: PHP + code: |- + $resp = $client->reindex([ + "body" => [ + "source" => [ + "index" => "my-index-000001", + ], + "dest" => [ + "index" => "my-new-index-000001", + ], + "script" => [ + "source" => "ctx._source.tag = ctx._source.remove(\"flag\")", + ], + ], + ]); + - language: curl + code: + "curl -X POST -H \"Authorization: ApiKey $ELASTIC_API_KEY\" -H \"Content-Type: application/json\" -d + '{\"source\":{\"index\":\"my-index-000001\"},\"dest\":{\"index\":\"my-new-index-000001\"},\"script\":{\"source\":\"ctx._sourc\ + e.tag = ctx._source.remove(\\\"flag\\\")\"}}' \"$ELASTICSEARCH_URL/_reindex\"" diff --git a/specification/security/query_api_keys/examples/request/QueryApiKeysRequestExample2.yaml b/specification/security/query_api_keys/examples/request/QueryApiKeysRequestExample2.yaml new file mode 100644 index 0000000000..c593fb136d --- /dev/null +++ b/specification/security/query_api_keys/examples/request/QueryApiKeysRequestExample2.yaml @@ -0,0 +1,308 @@ +summary: Query API keys with pagination +method_request: GET /_security/_query/api_key +description: > + Run `GET /_security/_query/api_key`. Use a `bool` query to issue complex logical conditions and use `from`, `size`, and `sort` to + help paginate the result. For example, the API key name must begin with `app1-key-` and must not be `app1-key-01`. It must be + owned by a username with the wildcard pattern `org-*-user` and the `environment` metadata field must have a `production` value. + The offset to begin the search result is the twentieth (zero-based index) API key. The page size of the response is 10 API keys. + The result is first sorted by creation date in descending order, then by name in ascending order. +# type: request +value: |- + { + "query": { + "bool": { + "must": [ + { + "prefix": { + "name": "app1-key-" + } + }, + { + "term": { + "invalidated": "false" + } + } + ], + "must_not": [ + { + "term": { + "name": "app1-key-01" + } + } + ], + "filter": [ + { + "wildcard": { + "username": "org-*-user" + } + }, + { + "term": { + "metadata.environment": "production" + } + } + ] + } + }, + "from": 20, + "size": 10, + "sort": [ + { "creation": { "order": "desc", "format": "date_time" } }, + "name" + ] + } +alternatives: + - language: Python + code: |- + resp = client.security.query_api_keys( + query={ + "bool": { + "must": [ + { + "prefix": { + "name": "app1-key-" + } + }, + { + "term": { + "invalidated": "false" + } + } + ], + "must_not": [ + { + "term": { + "name": "app1-key-01" + } + } + ], + "filter": [ + { + "wildcard": { + "username": "org-*-user" + } + }, + { + "term": { + "metadata.environment": "production" + } + } + ] + } + }, + from=20, + size=10, + sort=[ + { + "creation": { + "order": "desc", + "format": "date_time" + } + }, + "name" + ], + ) + - language: JavaScript + code: |- + const response = await client.security.queryApiKeys({ + query: { + bool: { + must: [ + { + prefix: { + name: "app1-key-", + }, + }, + { + term: { + invalidated: "false", + }, + }, + ], + must_not: [ + { + term: { + name: "app1-key-01", + }, + }, + ], + filter: [ + { + wildcard: { + username: "org-*-user", + }, + }, + { + term: { + "metadata.environment": "production", + }, + }, + ], + }, + }, + from: 20, + size: 10, + sort: [ + { + creation: { + order: "desc", + format: "date_time", + }, + }, + "name", + ], + }); + - language: Ruby + code: |- + response = client.security.query_api_keys( + body: { + "query": { + "bool": { + "must": [ + { + "prefix": { + "name": "app1-key-" + } + }, + { + "term": { + "invalidated": "false" + } + } + ], + "must_not": [ + { + "term": { + "name": "app1-key-01" + } + } + ], + "filter": [ + { + "wildcard": { + "username": "org-*-user" + } + }, + { + "term": { + "metadata.environment": "production" + } + } + ] + } + }, + "from": 20, + "size": 10, + "sort": [ + { + "creation": { + "order": "desc", + "format": "date_time" + } + }, + "name" + ] + } + ) + - language: PHP + code: |- + $resp = $client->security()->queryApiKeys([ + "body" => [ + "query" => [ + "bool" => [ + "must" => array( + [ + "prefix" => [ + "name" => "app1-key-", + ], + ], + [ + "term" => [ + "invalidated" => "false", + ], + ], + ), + "must_not" => array( + [ + "term" => [ + "name" => "app1-key-01", + ], + ], + ), + "filter" => array( + [ + "wildcard" => [ + "username" => "org-*-user", + ], + ], + [ + "term" => [ + "metadata.environment" => "production", + ], + ], + ), + ], + ], + "from" => 20, + "size" => 10, + "sort" => array( + [ + "creation" => [ + "order" => "desc", + "format" => "date_time", + ], + ], + "name", + ), + ], + ]); + - language: curl + code: + "curl -X GET -H \"Authorization: ApiKey $ELASTIC_API_KEY\" -H \"Content-Type: application/json\" -d + '{\"query\":{\"bool\":{\"must\":[{\"prefix\":{\"name\":\"app1-key-\"}},{\"term\":{\"invalidated\":\"false\"}}],\"must_not\":[{\ + \"term\":{\"name\":\"app1-key-01\"}}],\"filter\":[{\"wildcard\":{\"username\":\"org-*-user\"}},{\"term\":{\"metadata.environm\ + ent\":\"production\"}}]}},\"from\":20,\"size\":10,\"sort\":[{\"creation\":{\"order\":\"desc\",\"format\":\"date_time\"}},\"na\ + me\"]}' \"$ELASTICSEARCH_URL/_security/_query/api_key\"" + - language: Java + code: | + client.security().queryApiKeys(q -> q + .from(20) + .query(qu -> qu + .bool(b -> b + .filter(List.of(Query.of(que -> que + .wildcard(w -> w + .field("username") + .value("org-*-user") + )),Query.of(quer -> quer + .term(t -> t + .field("metadata.environment") + .value(FieldValue.of("production")) + )))) + .must(List.of(Query.of(query -> query + .prefix(p -> p + .field("name") + .value("app1-key-") + )),Query.of(query1 -> query1 + .term(t -> t + .field("invalidated") + .value(FieldValue.of("false")) + )))) + .mustNot(m -> m + .term(t -> t + .field("name") + .value(FieldValue.of("app1-key-01")) + ) + ) + ) + ) + .size(10) + .sort(List.of(SortOptions.of(s -> s + .field(f -> f + .field("creation") + .order(SortOrder.Desc) + .format("date_time") + )),SortOptions.of(so -> so + .field(f -> f + .field("name") + )))) + ); diff --git a/specification/security/query_api_keys/examples/request/QueryApiKeysRequestExample3.yaml b/specification/security/query_api_keys/examples/request/QueryApiKeysRequestExample3.yaml new file mode 100644 index 0000000000..0040fb82a5 --- /dev/null +++ b/specification/security/query_api_keys/examples/request/QueryApiKeysRequestExample3.yaml @@ -0,0 +1,77 @@ +summary: Query API keys by name +method_request: GET /_security/_query/api_key +description: Run `GET /_security/_query/api_key` to retrieve the API key by name. +# type: request +value: |- + { + "query": { + "term": { + "name": { + "value": "application-key-1" + } + } + } + } +alternatives: + - language: Python + code: |- + resp = client.security.query_api_keys( + query={ + "term": { + "name": { + "value": "application-key-1" + } + } + }, + ) + - language: JavaScript + code: |- + const response = await client.security.queryApiKeys({ + query: { + term: { + name: { + value: "application-key-1", + }, + }, + }, + }); + - language: Ruby + code: |- + response = client.security.query_api_keys( + body: { + "query": { + "term": { + "name": { + "value": "application-key-1" + } + } + } + } + ) + - language: PHP + code: |- + $resp = $client->security()->queryApiKeys([ + "body" => [ + "query" => [ + "term" => [ + "name" => [ + "value" => "application-key-1", + ], + ], + ], + ], + ]); + - language: curl + code: + 'curl -X GET -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d + ''{"query":{"term":{"name":{"value":"application-key-1"}}}}'' "$ELASTICSEARCH_URL/_security/_query/api_key"' + - language: Java + code: | + client.security().queryApiKeys(q -> q + .query(qu -> qu + .term(t -> t + .field("name") + .value(FieldValue.of("application-key-1")) + ) + ) + ); diff --git a/specification/security/query_api_keys/examples/response/QueryApiKeysResponseExample1.yaml b/specification/security/query_api_keys/examples/response/QueryApiKeysResponseExample1.yaml new file mode 100644 index 0000000000..8bc50ab61c --- /dev/null +++ b/specification/security/query_api_keys/examples/response/QueryApiKeysResponseExample1.yaml @@ -0,0 +1,53 @@ +summary: Query API keys by ID +description: > + A successful response from `GET /_security/_query/api_key?with_limited_by=true`. + The `limited_by` details are the owner user's permissions associated with the API key. + It is a point-in-time snapshot captured at creation and subsequent updates. + An API key's effective permissions are an intersection of its assigned privileges and the owner user's permissions. +# type: response +# response_code: +value: |- + { + "api_keys": [ + { + "id": "VuaCfGcBCdbkQm-e5aOx", + "name": "application-key-1", + "creation": 1548550550158, + "expiration": 1548551550158, + "invalidated": false, + "username": "myuser", + "realm": "native1", + "realm_type": "native", + "metadata": { + "application": "my-application" + }, + "role_descriptors": { }, + "limited_by": [ + { + "role-power-user": { + "cluster": [ + "monitor" + ], + "indices": [ + { + "names": [ + "*" + ], + "privileges": [ + "read" + ], + "allow_restricted_indices": false + } + ], + "applications": [ ], + "run_as": [ ], + "metadata": { }, + "transient_metadata": { + "enabled": true + } + } + } + ] + } + ] + } diff --git a/specification/security/query_api_keys/examples/response/QueryApiKeysResponseExample2.yaml b/specification/security/query_api_keys/examples/response/QueryApiKeysResponseExample2.yaml new file mode 100644 index 0000000000..c932dd950f --- /dev/null +++ b/specification/security/query_api_keys/examples/response/QueryApiKeysResponseExample2.yaml @@ -0,0 +1,46 @@ +summary: Query API keys with pagination +description: > + An abbreviated response from `GET /_security/_query/api_key` that contains a list of matched API keys along with their sort values. + The first sort value is creation time, which is displayed in `date_time` format. + The second sort value is the API key name. +# type: response +# response_code: +value: |- + { + "total": 100, + "count": 10, + "api_keys": [ + { + "id": "CLXgVnsBOGkf8IyjcXU7", + "name": "app1-key-79", + "creation": 1629250154811, + "invalidated": false, + "username": "org-admin-user", + "realm": "native1", + "metadata": { + "environment": "production" + }, + "role_descriptors": { }, + "_sort": [ + "2021-08-18T01:29:14.811Z", + "app1-key-79" + ] + }, + { + "id": "BrXgVnsBOGkf8IyjbXVB", + "name": "app1-key-78", + "creation": 1629250153794, + "invalidated": false, + "username": "org-admin-user", + "realm": "native1", + "metadata": { + "environment": "production" + }, + "role_descriptors": { }, + "_sort": [ + "2021-08-18T01:29:13.794Z", + "app1-key-78" + ] + } + ] + } diff --git a/specification/security/query_api_keys/examples/response/QueryApiKeysResponseExample3.yaml b/specification/security/query_api_keys/examples/response/QueryApiKeysResponseExample3.yaml new file mode 100644 index 0000000000..5108837276 --- /dev/null +++ b/specification/security/query_api_keys/examples/response/QueryApiKeysResponseExample3.yaml @@ -0,0 +1,65 @@ +summary: Query all API keys +description: > + A successful response from `GET /_security/_query/api_key`. + It includes the role descriptors that are assigned to each API key when it was created or last updated. + Note that an API key's effective permissions are an intersection of its assigned privileges and the point-in-time snapshot of the owner user's permissions. + An empty role descriptors object means the API key inherits the owner user's permissions. +# type: response +# response_code: +value: |- + { + "total": 3, + "count": 3, + "api_keys": [ + { + "id": "nkvrGXsB8w290t56q3Rg", + "name": "my-api-key-1", + "creation": 1628227480421, + "expiration": 1629091480421, + "invalidated": false, + "username": "elastic", + "realm": "reserved", + "realm_type": "reserved", + "metadata": { + "letter": "a" + }, + "role_descriptors": { + "role-a": { + "cluster": [ + "monitor" + ], + "indices": [ + { + "names": [ + "index-a" + ], + "privileges": [ + "read" + ], + "allow_restricted_indices": false + } + ], + "applications": [ ], + "run_as": [ ], + "metadata": { }, + "transient_metadata": { + "enabled": true + } + } + } + }, + { + "id": "oEvrGXsB8w290t5683TI", + "name": "my-api-key-2", + "creation": 1628227498953, + "expiration": 1628313898953, + "invalidated": false, + "username": "elastic", + "realm": "reserved", + "metadata": { + "letter": "b" + }, + "role_descriptors": { } + } + ] + }