【问题标题】:Add geoIP data to old data from Elasticsearch index将 geoIP 数据添加到 Elasticsearch 索引中的旧数据
【发布时间】:2021-11-16 15:28:38
【问题描述】:

我最近在 Elasticsearch 的摄取管道中添加了一个 GeoIP 处理器。这很好用,并为新摄取的文档添加了新字段。 我想通过对索引执行 _update_by_query 将 GeoIP 字段添加到旧数据中,但是,它似乎不接受“处理器”作为参数。

我想做的是这样的:

POST my_index*/_update_by_query
{
 "refresh": true,
 "processors": [
   {
     "geoip" : {
        "field": "doc['client_ip']",
        "target_field" : "geo",
        "database_file" : "GeoLite2-City.mmdb",
        "properties":["continent_name", "country_iso_code", "country_name", "city_name", "timezone", "location"]
    }
   }
 ],
 "script": {
  "day_of_week": {
    "type": "long",
    "script": "emit(doc['@timestamp'].value.withZoneSameInstant(ZoneId.of(doc['geo.timezone'])).getDayOfWeek().getValue())"
  },
  "hour_of_day": {
    "type": "long",
    "script": "emit(doc['@timestamp'].value.withZoneSameInstant(ZoneId.of(doc['geo.timezone'])).getHour())"
  },
  "office_hours": {
    "script": "if (doc['day_of_week'].value< 6 && doc['day_of_week'].value > 0) {if (doc['hour_of_day'].value> 7 && doc['hour_of_day'].value<19) {return 1;} else {return -1;} } else {return -1;}"
  }
 }
}

我收到以下错误:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "parse_exception",
        "reason" : "Expected one of [source] or [id] fields, but found none"
      }
    ],
    "type" : "parse_exception",
    "reason" : "Expected one of [source] or [id] fields, but found none"
  },
  "status" : 400
}

【问题讨论】:

    标签: elasticsearch geoip update-by-query


    【解决方案1】:

    由于您已准备好摄取管道,您只需在调用 _update_by_query 端点时引用它,如下所示:

    POST my_index*/_update_by_query?pipeline=my-pipeline
                                        ^
                                        |
                                     add this
    

    【讨论】:

    • 我在运行它时没有收到任何错误,但我也没有看到在 Kibana 中填充了旧数据的字段。我也将字段添加到映射中,但到目前为止没有成功。
    • 您确定这些文档有client_ip 字段并且是公共IP 地址吗?
    • 确实如此。我认为这就是发生的事情:我在旧的摄取管道中实现了新的 geoip 和脚本处理器,并且对于新摄取的数据运行良好。但是对于旧数据,为了避免在旧管道中重新运行旧处理器,我将新处理器放在新的摄取管道中,并在新管道上运行 update_by_query。问题是,我认为这个新管道不是从logstash路由到的。所以它没有任何效果。我在旧管道上运行了 update_by_query,现在新字段已填充。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    • 1970-01-01
    • 2016-08-29
    • 2019-01-16
    相关资源
    最近更新 更多