elasticsearch Elasticsearch:摄取节点-使用脚本处理器填充索引字段
我需要通过转换其他索引字段的数据,用格式化字符串填充一些索引字段。 为此,我定义了一个包含脚本处理器的摄取管道。万事俱备;但是在索引时,目标字段不会填充任何值 索引:
elasticsearch Elasticsearch:摄取节点-使用脚本处理器填充索引字段,
elasticsearch,
elasticsearch,我需要通过转换其他索引字段的数据,用格式化字符串填充一些索引字段。 为此,我定义了一个包含脚本处理器的摄取管道。万事俱备;但是在索引时,目标字段不会填充任何值 索引: PUT my_index { "mappings": { "product": { "properties": { "product_name": {"type": "text", "index": true}, "formatted_product_name": {"typ
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"}
}
}
}
}
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"}
有了这个示例索引,我想获得由摄取管道逻辑填充的字段格式化的产品名称
和格式化的日期
摄取管道(无任何实际逻辑):
查询:
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"}
}
}
}
}
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"}
获取我的索引/产品/\u搜索
{
"query": {
"match_all": {}
}
}
备注:以下管道工程。但这不会扩大规模。因此,我正在寻找一种方法,通过动态处理一些源索引字段的值来填充一组目标字段
PUT _ingest/pipeline/product_data_preprocessing
{
"processors" : [
{"script": {
"lang": "painless",
"inline": "ctx.formatted_date = ctx.production_date"
}}
]
}
那么,有没有一种方法可以定义一个(无痛的)在摄取管道处理器中编写脚本,通过定义一组源字段和一组目标字段以及适当的处理逻辑来动态填充一组索引字段?我一直在寻找如何使用摄取管道添加一个
计数
字段,遇到了您的问题。经过大量的尝试和错误,我成功地编写了一个管道,它通过换行来拆分字符串,然后在拆分数组中添加一个字段来表示条目数。不确定是否有用,但不管怎样,它在这里
{
"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
将是前两个处理器的结果感谢您的努力。问题不在于文本操作部分,而在于如何创建索引字段集合以及如何使用它们。