问题描述
我创建了这样的ElasticSearch转换:
"source": {
"index": "input_index"
},"dest" : {
"index" : "output_index"
},"pivot": {
"group_by": {
"device_id": { "terms": { "field": "device_id.keyword" }}
},"aggregations": {
"@timestamp": {
"max": {
"field": "@timestamp"
}
},"latest_doc": {
"scripted_metric": {
"init_script": ...,"map_script": ... }","combine_script": "return state","reduce_script": .... return last_doc (last_doc contains document from input_index)
}
}
}
}
这很好用,但是目标索引中的所有字段都以“ latest_doc”开头。 有没有办法防止在此last_doc标签之前添加字段名?
(否则我必须对输入索引和输出索引使用不同的索引模板)
解决方法
为任何想知道的人找到了一种解决方法:
添加了摄取管道:
PUT _ingest/pipeline/remove_trailing_
{
"processors": [{
"script": {
"source": """
for(item in ctx['latest_doc'].entrySet()) {
def f1 = 'latest_doc.' + item.getKey();
def f2 = item.getKey();
ctx[f2] = item.getValue();
}
ctx.remove('latest_doc');
"""
}
}
]
}