2017-02-21 71 views
1

我需要通过转换其他索引字段的数据来填充某些具有格式化字符串的索引字段。 为了做到这一点,我定义了一个包含脚本处理器的摄取管道。一切都在编译;但在建立索引时,目标字段没有填充任何值。Elasticsearch:摄入节点 - 使用脚本处理器填充索引字段

指数

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_nameformatted_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"} 

查询

GET my_index /产品/ _search

{ 
    "query": { 
     "match_all": {} 
    } 
} 

备注:以下管道工作。但是这不会扩展。因此,我正在寻找一种通过以动态方式处理一些源索引字段的值来填充一组目标字段的方法。

PUT _ingest/pipeline/product_data_preprocessing 
{ 
    "processors" : [ 
{"script": { 
    "lang": "painless", 
    "inline": "ctx.formatted_date = ctx.production_date" 
    }} 
    ] 
} 

那么,有一种方法来定义在摄取流水线处理器(无痛)脚本通过定义一组源字段和一组目标字段加上适当的处理逻辑的动态填充的一组索引字段的?

回答

0

我一直在寻找如何使用摄取管道添加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将是前2个处理器

+1

谢谢你的努力的结果。问题不在于文本操作部分,而在于如何创建索引字段集合以及如何使用它们。 –