如何解决ElasticSearch转换,scripted_metric,无嵌套字段名
我创建了这样的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');
"""
}
}
]
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。