Skip to content

Commit bee9d90

Browse files
Re-add API example files (#4670) (#4916)
(cherry picked from commit f35b154) Co-authored-by: Charlotte Hoblik <[email protected]>
1 parent 5e29007 commit bee9d90

17 files changed

+1692
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
summary: Reindex with Painless
2+
method_request: POST _reindex
3+
description: >
4+
You can use Painless to reindex daily indices to apply a new template to the existing documents. The script extracts the date from
5+
the index name and creates a new index with `-1` appended. For example, all data from `metricbeat-2016.05.31` will be reindexed
6+
into `metricbeat-2016.05.31-1`.
7+
# type: request
8+
value: "{
9+
10+
\ \"source\": {
11+
12+
\ \"index\": \"metricbeat-*\"
13+
14+
\ },
15+
16+
\ \"dest\": {
17+
18+
\ \"index\": \"metricbeat\"
19+
20+
\ },
21+
22+
\ \"script\": {
23+
24+
\ \"lang\": \"painless\",
25+
26+
\ \"source\": \"ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'\"
27+
28+
\ }
29+
30+
}"
31+
alternatives:
32+
- language: Python
33+
code: |-
34+
resp = client.reindex(
35+
source={
36+
"index": "metricbeat-*"
37+
},
38+
dest={
39+
"index": "metricbeat"
40+
},
41+
script={
42+
"lang": "painless",
43+
"source": "ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'"
44+
},
45+
)
46+
- language: JavaScript
47+
code: |-
48+
const response = await client.reindex({
49+
source: {
50+
index: "metricbeat-*",
51+
},
52+
dest: {
53+
index: "metricbeat",
54+
},
55+
script: {
56+
lang: "painless",
57+
source:
58+
"ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'",
59+
},
60+
});
61+
- language: Ruby
62+
code: |-
63+
response = client.reindex(
64+
body: {
65+
"source": {
66+
"index": "metricbeat-*"
67+
},
68+
"dest": {
69+
"index": "metricbeat"
70+
},
71+
"script": {
72+
"lang": "painless",
73+
"source": "ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'"
74+
}
75+
}
76+
)
77+
- language: PHP
78+
code: >-
79+
$resp = $client->reindex([
80+
"body" => [
81+
"source" => [
82+
"index" => "metricbeat-*",
83+
],
84+
"dest" => [
85+
"index" => "metricbeat",
86+
],
87+
"script" => [
88+
"lang" => "painless",
89+
"source" => "ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'",
90+
],
91+
],
92+
]);
93+
- language: curl
94+
code:
95+
"curl -X POST -H \"Authorization: ApiKey $ELASTIC_API_KEY\" -H \"Content-Type: application/json\" -d
96+
'{\"source\":{\"index\":\"metricbeat-*\"},\"dest\":{\"index\":\"metricbeat\"},\"script\":{\"lang\":\"painless\",\"source\":\"\
97+
ctx._index = '\"'\"'metricbeat-'\"'\"' + (ctx._index.substring('\"'\"'metricbeat-'\"'\"'.length(), ctx._index.length())) +
98+
'\"'\"'-1'\"'\"'\"}}' \"$ELASTICSEARCH_URL/_reindex\""
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
summary: Reindex a random subset
2+
method_request: POST _reindex
3+
description: >
4+
Run `POST _reindex` to extract a random subset of the source for testing. You might need to adjust the `min_score` value depending
5+
on the relative amount of data extracted from source.
6+
# type: request
7+
value: "{
8+
9+
\ \"max_docs\": 10,
10+
11+
\ \"source\": {
12+
13+
\ \"index\": \"my-index-000001\",
14+
15+
\ \"query\": {
16+
17+
\ \"function_score\" : {
18+
19+
\ \"random_score\" : {},
20+
21+
\ \"min_score\" : 0.9
22+
23+
\ }
24+
25+
\ }
26+
27+
\ },
28+
29+
\ \"dest\": {
30+
31+
\ \"index\": \"my-new-index-000001\"
32+
33+
\ }
34+
35+
}"
36+
alternatives:
37+
- language: Python
38+
code: |-
39+
resp = client.reindex(
40+
max_docs=10,
41+
source={
42+
"index": "my-index-000001",
43+
"query": {
44+
"function_score": {
45+
"random_score": {},
46+
"min_score": 0.9
47+
}
48+
}
49+
},
50+
dest={
51+
"index": "my-new-index-000001"
52+
},
53+
)
54+
- language: JavaScript
55+
code: |-
56+
const response = await client.reindex({
57+
max_docs: 10,
58+
source: {
59+
index: "my-index-000001",
60+
query: {
61+
function_score: {
62+
random_score: {},
63+
min_score: 0.9,
64+
},
65+
},
66+
},
67+
dest: {
68+
index: "my-new-index-000001",
69+
},
70+
});
71+
- language: Ruby
72+
code: |-
73+
response = client.reindex(
74+
body: {
75+
"max_docs": 10,
76+
"source": {
77+
"index": "my-index-000001",
78+
"query": {
79+
"function_score": {
80+
"random_score": {},
81+
"min_score": 0.9
82+
}
83+
}
84+
},
85+
"dest": {
86+
"index": "my-new-index-000001"
87+
}
88+
}
89+
)
90+
- language: PHP
91+
code: |-
92+
$resp = $client->reindex([
93+
"body" => [
94+
"max_docs" => 10,
95+
"source" => [
96+
"index" => "my-index-000001",
97+
"query" => [
98+
"function_score" => [
99+
"random_score" => new ArrayObject([]),
100+
"min_score" => 0.9,
101+
],
102+
],
103+
],
104+
"dest" => [
105+
"index" => "my-new-index-000001",
106+
],
107+
],
108+
]);
109+
- language: curl
110+
code:
111+
"curl -X POST -H \"Authorization: ApiKey $ELASTIC_API_KEY\" -H \"Content-Type: application/json\" -d
112+
'{\"max_docs\":10,\"source\":{\"index\":\"my-index-000001\",\"query\":{\"function_score\":{\"random_score\":{},\"min_score\":\
113+
0.9}}},\"dest\":{\"index\":\"my-new-index-000001\"}}' \"$ELASTICSEARCH_URL/_reindex\""
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
summary: Reindex modified documents
2+
method_request: POST _reindex
3+
description: >
4+
Run `POST _reindex` to modify documents during reindexing. This example bumps the version of the source document.
5+
# type: request
6+
value: "{
7+
8+
\ \"source\": {
9+
10+
\ \"index\": \"my-index-000001\"
11+
12+
\ },
13+
14+
\ \"dest\": {
15+
16+
\ \"index\": \"my-new-index-000001\",
17+
18+
\ \"version_type\": \"external\"
19+
20+
\ },
21+
22+
\ \"script\": {
23+
24+
\ \"source\": \"if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}\",
25+
26+
\ \"lang\": \"painless\"
27+
28+
\ }
29+
30+
}"
31+
alternatives:
32+
- language: Python
33+
code: |-
34+
resp = client.reindex(
35+
source={
36+
"index": "my-index-000001"
37+
},
38+
dest={
39+
"index": "my-new-index-000001",
40+
"version_type": "external"
41+
},
42+
script={
43+
"source": "if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}",
44+
"lang": "painless"
45+
},
46+
)
47+
- language: JavaScript
48+
code: |-
49+
const response = await client.reindex({
50+
source: {
51+
index: "my-index-000001",
52+
},
53+
dest: {
54+
index: "my-new-index-000001",
55+
version_type: "external",
56+
},
57+
script: {
58+
source:
59+
"if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}",
60+
lang: "painless",
61+
},
62+
});
63+
- language: Ruby
64+
code: |-
65+
response = client.reindex(
66+
body: {
67+
"source": {
68+
"index": "my-index-000001"
69+
},
70+
"dest": {
71+
"index": "my-new-index-000001",
72+
"version_type": "external"
73+
},
74+
"script": {
75+
"source": "if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}",
76+
"lang": "painless"
77+
}
78+
}
79+
)
80+
- language: PHP
81+
code: |-
82+
$resp = $client->reindex([
83+
"body" => [
84+
"source" => [
85+
"index" => "my-index-000001",
86+
],
87+
"dest" => [
88+
"index" => "my-new-index-000001",
89+
"version_type" => "external",
90+
],
91+
"script" => [
92+
"source" => "if (ctx._source.foo == 'bar') {ctx._version++; ctx._source.remove('foo')}",
93+
"lang" => "painless",
94+
],
95+
],
96+
]);
97+
- language: curl
98+
code:
99+
"curl -X POST -H \"Authorization: ApiKey $ELASTIC_API_KEY\" -H \"Content-Type: application/json\" -d
100+
'{\"source\":{\"index\":\"my-index-000001\"},\"dest\":{\"index\":\"my-new-index-000001\",\"version_type\":\"external\"},\"scr\
101+
ipt\":{\"source\":\"if (ctx._source.foo == '\"'\"'bar'\"'\"') {ctx._version++;
102+
ctx._source.remove('\"'\"'foo'\"'\"')}\",\"lang\":\"painless\"}}' \"$ELASTICSEARCH_URL/_reindex\""

0 commit comments

Comments
 (0)