【发布时间】:2021-10-02 19:36:49
【问题描述】:
我根据 projectId 创建 idice,如下所示:
//直接调用reindex API就可以了
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'
}
}
"""
}
}
但是当我想像这样使用管道重新索引时:
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'
}
}
"""
}
}
]
}
和:
POST _reindex
{
"conflicts": "proceed",
"source": {
"index": "xxxxxx-rlk-test1-2021-07-22"
},
"dest": {
"index": "xxxxxx",
"pipeline": "group-by-projectid-pipeline",
"op_type": "create"
}
}
然后elasticsearch说(关于(ctx._index.substring('xxxxxx-rlk-test-'.length(), ctx._index.length()))):
"type" : "string_index_out_of_bounds_exception", “原因”:“开始 16,结束 6,长度 6”
提前感谢您的帮助!
【问题讨论】:
标签: elasticsearch elastic-stack elasticsearch-5 elasticsearch-dsl elasticsearch-opendistro