【问题标题】:Elasticsearch: ingest node - use script processor to populate index fieldsElasticsearch:摄取节点 - 使用脚本处理器填充索引字段
【发布时间】:2017-07-11 12:25:54
【问题描述】:

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

索引

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/product/_search

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

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

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

那么有没有办法在摄取管道处理器中定义(无痛)脚本,通过定义一组源字段和一组目标字段以及适当的处理逻辑来动态填充一组索引字段?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

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

    【讨论】:

    • 感谢您的努力。问题不在于文本操作部分,而在于如何创建索引字段的集合以及如何使用它们。
    猜你喜欢
    • 2021-02-27
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-15
    • 1970-01-01
    • 2017-04-13
    相关资源
    最近更新 更多