Skip to content

Re-add API example files #4670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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\""
Original file line number Diff line number Diff line change
@@ -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\""
Original file line number Diff line number Diff line change
@@ -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\""
Loading