I have to reindex dynamically like the code below.
curl -XPOST 'http://localhost:9200/_reindex' -H 'Content-Type: application/json'
-d '
{
"source": {
"index": "apache-*",
"query": {
"bool": {
"must": [
{
"range": {
"new_time": {
"gte": "now-30d"
}
}
},
{
"range": {
"new_time": {
"lt": "now"
}
}
},
{
"range": {
"duration": {
"gte": "10000"
}
}
}
]
}
}
},
"dest": {
"index": "duration"
},
"script": {
"lang": "painless",
"inline": "ctx._index = 'apache-' + (ctx._index.substring('apache-'.length(), ctx._index.length())) + '-1'"
}
}'
I refer to this code on your web site(https://www.elastic.co/guide/en/elasticsearch/reference/5.4/docs-reindex.html)
POST _reindex
{
"source": {
"index": "metricbeat-*"
},
"dest": {
"index": "metricbeat"
},
"script": {
"lang": "painless",
"inline": "ctx._index = 'metricbeat-' + (ctx._index.substring('metricbeat-'.length(), ctx._index.length())) + '-1'"
}
}
but It keeps giving me this kind of error.
{"error":{"root_cause":[{"type":"script_exception","reason":"compile error","script_stack":["... ._index.substring(apache-.length(), ctx._index.len ..."," ^---- HERE"],"script":"ctx._index = apache- + (ctx._index.substring(apache-.length(), ctx._index.length())) + -1","lang":"painless"}],"type":"script_exception","reason":"compile error","script_stack":["... ._index.substring(apache-.length(), ctx._index.len ..."," ^---- HERE"],"script":"ctx._index = apache- + (ctx._index.substring(apache-.length(), ctx._index.length())) + -1","lang":"painless","caused_by":{"type":"illegal_argument_exception","reason":"invalid sequence of tokens near ['.'].","caused_by":{"type":"no_viable_alt_exception","reason":null}}
I don't know what is wrong with my code. I hope you could help me. Thank you in advance.