我需要通过转换其他索引字段的数据,用格式化的字符串填充一些索引字段。为了做到这一点,我定义了一个包含脚本处理器的吞食管道。所有内容都会编译;但是,在索引目标字段时,不会填充任何值。
指数
PUT my_index
{
"mappings": {
"product": {
"properties": {
"product_name": {"type": "text", "index": true},
"formatted_product_name": {"type": "keyword", "index": true},
"production_date": {"type": "keyword", "index": "true"},
"formatted_date": {"type": "keyword", "index": "true"}
}
}
}
}有了这个示例索引之后,我想让字段formatted_product_name和formatted_date由最吞食的管道逻辑填充。
吞食管道(没有任何真正的逻辑):
PUT _ingest/pipeline/product_data_preprocessing
{
"processors" : [
{"script": {
"lang": "painless",
"inline": "def source_fields = [ctx.product_name, ctx.production_date]; def target_fields = [ctx.formatted_product_name, ctx.formatted_date]; for(def i=0; i<source_fields.length; i++) { target_fields[i] = source_fields[i]; }"
}}
]
}数据
PUT _bulk?pipeline=product_data_preprocessing
{"index": {"_index": "my_index", "_type": "product", "_id": "1"}}
{"product_name": "ipad", "production_date": "2017-02-17"}
{"index": {"_index": "my_index", "_type": "product", "_id": "2"}}
{"product_name": "tv", "production_date": "2017-10-07"}查询
获取我的索引/产品/搜索
{
"query": {
"match_all": {}
}
}备注:下面的管道工作。但这不会扩大规模。因此,我正在寻找一种方法,通过动态处理某些源索引字段的值来填充一组目标字段。
PUT _ingest/pipeline/product_data_preprocessing
{
"processors" : [
{"script": {
"lang": "painless",
"inline": "ctx.formatted_date = ctx.production_date"
}}
]
}那么,是否有一种方法来定义一个(无痛的)脚本,通过定义一组源字段和一组目标字段,再加上适当的处理逻辑,动态地填充一组索引字段?
发布于 2017-02-28 17:36:28
我一直在寻找如何使用一个吞食管道添加一个count字段,并遇到了您的问题。经过多次尝试和错误之后,我成功地编写了一个管道,该管道将字符串拆分为换行符,然后为拆分数组中的条目数添加一个字段。不知道能不能帮上忙,但反正在这里
{
"description" : "split content from Tika into rows",
"processors" : [
{
"gsub": {
"field": "content",
"pattern": "\\t+",
"replacement": " "
}
},
{
"split": {
"field": "content",
"separator": "\\n"
}
},
{
"script": {
"inline": "ctx.nrows = ctx.content.size()"
}
}
]
}注意,ctx.content将是前两个处理器的结果。
https://stackoverflow.com/questions/42374813
复制相似问题