简体   繁体   English

将 geoIP 数据添加到来自 Elasticsearch 索引的旧数据

[英]Add geoIP data to old data from Elasticsearch index

I recently added a GeoIP processor to my ingestion pipeline in Elasticsearch.我最近在 Elasticsearch 的摄取管道中添加了一个 GeoIP 处理器。 this works well and adds new fields to the newly ingested documents.这很有效,并向新摄取的文档添加了新字段。 I wanted to add the GeoIP fields to older data by doing an _update_by_query on an index, however, it seems that it doesn't accept "processors" as a parameter.我想通过对索引执行 _update_by_query 将 GeoIP 字段添加到旧数据中,但是,它似乎不接受“处理器”作为参数。

What I want to do is something like this:我想做的是这样的:

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

I receive the following error:我收到以下错误:

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

Since you have the ingestion pipeline ready, you simply need to reference it in your call to the _update_by_query endpoint, like this:由于您已准备好摄取管道,您只需在对_update_by_query端点的调用中引用它,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM