i create idices based on projectId like so:
//By calling reindex API directly,it works fine
POST _reindex?wait_for_completion=false
{
"conflicts": "proceed",
"source": {
"index": "xxxxx-rlk-test1-2021-07-22"
},
"dest": {
"index": "xxxxxx",
"op_type": "create"
},
"script": {
"lang": "painless",
"source": """
if (ctx._source.kubernetes != null){
if (ctx._source.kubernetes.namespace_labels['field_cattle_io/projectId'] != null){
ctx._index = 'xxxxxx-rlk-'+ (ctx._source.kubernetes.namespace_labels['field_cattle_io/projectId']) + '' + (ctx._index.substring('xxxxxx-rlk-test-'.length(), ctx._index.length()))
}else {
ctx._index = 'xxxxxx-rlk-'+ (ctx._source.kubernetes.namespace_labels['field_cattle_io/projectId']) +'-noproject'
}
}
"""
}
}
But when i would like to use reindex with pipeline like so:
PUT _ingest/pipeline/group-by-projectid-pipeline
{
"description": "this pipeline split indices by pipeline",
"processors": [
{
"script": {
"lang": "painless",
"source": """
if (ctx.kubernetes != null){
if (ctx.kubernetes.namespace_labels['field_cattle_io/projectId'] != null){
ctx._index = 'xxxxxx-rlk-'+ (ctx.kubernetes.namespace_labels['field_cattle_io/projectId']) +'' + (ctx._index.substring('xxxxxx-rlk-test-'.length(), ctx._index.length()))
}else {
ctx._index = 'xxxxxx-rlk-'+ (ctx.kubernetes.namespace_labels['field_cattle_io/projectId']) +'-noproject'
}
}
"""
}
}
]
}
and :
POST _reindex
{
"conflicts": "proceed",
"source": {
"index": "xxxxxx-rlk-test1-2021-07-22"
},
"dest": {
"index": "xxxxxx",
"pipeline": "group-by-projectid-pipeline",
"op_type": "create"
}
}
then elasticsearch says (about (ctx._index.substring('xxxxxx-rlk-test-'.length(), ctx._index.length()))):
"type" : "string_index_out_of_bounds_exception", "reason" : "begin 16, end 6, length 6"
Thank you in advance for your help!