# Filebeatで作成されるインデックスについて

**URL:** <https://discuss.elastic.co/t/filebeat/224017>\
**Category:** 日本語による質問・議論はこちら\
**Created:** [March 18, 2020, 2:51am UTC](https://discuss.elastic.co/t/filebeat/224017 "2020-03-18T02:51:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![111142](https://avatars.discourse-cdn.com/v4/letter/1/a9a28c/32.png) [@111142](https://discuss.elastic.co/u/111142)\
**Post date:** [March 18, 2020, 2:51am UTC](https://discuss.elastic.co/t/filebeat/224017/1 "2020-03-18T02:51:57Z")

</div>

filebeatの設定を下記のように行いモジュールごとにインデックスを分けてログを取り込んでいます。

```auto
output.elasticsearch:
  hosts: ["localhost:9200"]
  indices:
    - index: "paloalto-%{+yyyy.MM.dd}"
      when.equals:
        event.module: "panw"
    - index: "elasticsearch-%{+yyyy.MM.dd}"
      when.equals:
        event.module: "elasticsearch"

```

ログ自体は問題なく取り込め、様々なフィールドが自動で作成をされていますが、  
手動でフィールドを追加することは可能なのでしょうか。

具体的には、地理情報に国名を入れたいと思っています。  
logstashですと、geoip のフィルターで国名が入っていたため、filebeatの設定漏れかもしれませんので  
その場合は、設定項目を教えて頂けると幸いです。

```auto
      "geo": {
        "continent_name": "North America",
        "region_iso_code": "US-VA",
        "city_name": "Ashburn",
        "country_iso_code": "US",
        "region_name": "Virginia",
        "location": {
          "lon": -77.4728,
          "lat": 39.0481
        }
      },

```

ここに、country\_name を入れたい。

---

<div class="post-metadata">

**Author:** ![tsgkdt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsgkdt/32/39151_2.png) [@tsgkdt](https://discuss.elastic.co/u/tsgkdt)\
**Post date:** [March 18, 2020, 7:36am UTC](https://discuss.elastic.co/t/filebeat/224017/2 "2020-03-18T07:36:43Z")

</div>

filebeatからElasticsearchに送信したデータを加工するのは、Ingest Processorを使うと加工ができたかと思います。

お見受けしたところ、[geoip processor](https://www.elastic.co/guide/en/elasticsearch/reference/current/geoip-processor.html#geoip-processor)を使っていらっしゃるのではないでしょうか。

説明をよむと、country\_nameもGeoLite2 CityかCountryを使っていれば may be addedとあるので、追加されるように見えますが、何もしないと追加されませんでした。(7.6.1で確認)

> If the GeoLite2 City database is used, then the following fields may be added under the target\_field : ip , country\_iso\_code , country\_name, continent\_name, region\_iso\_code, region\_name , city\_name , timezone , latitude , longitude and location.

propertiesで明示的に取得する項目を指定するとcountry\_nameが出力されました。  
Pipelineのsimulationと結果を貼っておきます。

```auto
POST /_ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "geoip": {
          "field": "ip",
          "properties": [
            "ip",
            "country_iso_code",
            "country_name",
            "continent_name",
            "region_iso_code",
            "region_name",
            "city_name",
            "timezone",
            "location"
          ]
        }
      }
    ]
  },
  "docs": [
    {
      "_index": "forum0318",
      "_id": "id1",
      "_source": {
        "ip": "163.43.102.12"
      }
    }
  ]
}

```

country\_nameが出力されていることが確認できます。

```auto
{
  "docs" : [
    {
      "doc" : {
        "_index" : "forum0318",
        "_type" : "_doc",
        "_id" : "id1",
        "_source" : {
          "geoip" : {
            "continent_name" : "Asia",
            "region_iso_code" : "JP-27",
            "city_name" : "Osaka",
            "country_iso_code" : "JP",
            "timezone" : "Asia/Tokyo",
            "ip" : "163.43.102.12",
            "country_name" : "Japan",
            "region_name" : "Ōsaka",
            "location" : {
              "lon" : 135.5167,
              "lat" : 34.6833
            }
          },
          "ip" : "163.43.102.12"
        },
        "_ingest" : {
          "timestamp" : "2020-03-18T07:28:45.714869Z"
        }
      }
    }
  ]
}

```

もしgeoipをお使いであれば、上記が参考になるかもしれません。

---

<div class="post-metadata">

**Author:** ![111142](https://avatars.discourse-cdn.com/v4/letter/1/a9a28c/32.png) [@111142](https://discuss.elastic.co/u/111142)\
**Post date:** [March 18, 2020, 8:50am UTC](https://discuss.elastic.co/t/filebeat/224017/3 "2020-03-18T08:50:19Z")

</div>

回答ありがとうございます。  
早速試してみたいと思います。  
この場合、filebeatのモジュール内に定義されているものに対して  
上書きで設定が反映されるという認識であっていますでしょうか。

---

<div class="post-metadata">

**Author:** ![tsgkdt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsgkdt/32/39151_2.png) [@tsgkdt](https://discuss.elastic.co/u/tsgkdt)\
**Post date:** [March 18, 2020, 12:50pm UTC](https://discuss.elastic.co/t/filebeat/224017/4 "2020-03-18T12:50:11Z")

</div>

こんにちわ。

filebeatのmodule以下にあるpipelineの設定を変更することで対応可能かと思いますが、  
書き方がfilebeatの場合はyamlになっていて、先に紹介した直接pipelineを作成するときと異なるので読み替えは必要かと。

panwモジュールですと、以下にその設定があるかと思います。

`module/panw/panos/ingest/pipiline.yml`

箇所でいえば、このあたりかと思います。propertiesの指定については、AS Lookupの指定の方にちょうどよい見本がありますので、こちらを模してやればよろしいかと。

```auto
# Geolocation for source.
 - geoip:
     if: 'ctx?.source?.ip != null'
     field: source.ip
     target_field: source.geo

# Geolocation for destination.
 - geoip:
     if: 'ctx?.destination?.ip != null'
     field: destination.ip
     target_field: destination.geo

# IP Autonomous System (AS) Lookup
 - geoip:
     database_file: GeoLite2-ASN.mmdb
     field: source.ip
     target_field: source.as
     properties:
       - asn
       - organization_name
     ignore_missing: true

```

留意点としては、filebeat実行時にpipelineがなければ作成しますが、すでに作成されていた場合の挙動は上書きせずスルーになっています。  
このため、ちょこちょこファイルを変えて試したいというような場合でしたら、filebeat.ymlの設定でpipelineを上書きする設定にしておくと良いのではと思います。

```auto
# By default Ingest pipelines are not updated if a pipeline with the same ID
# already exists. If this option is enabled Filebeat overwrites pipelines
# everytime a new Elasticsearch connection is established.
filebeat.overwrite_pipelines: true # ←上書きする設定。デフォルトは上書きしない。

```

ご参考になれば幸いです。

---

<div class="post-metadata">

**Author:** ![111142](https://avatars.discourse-cdn.com/v4/letter/1/a9a28c/32.png) [@111142](https://discuss.elastic.co/u/111142)\
**Post date:** [March 19, 2020, 3:00am UTC](https://discuss.elastic.co/t/filebeat/224017/5 "2020-03-19T03:00:36Z")

</div>

詳細な情報ありがとうございます。  
下記設定を追加することで希望通りの動作をしました。  
ありがとうございます。

```auto
 - geoip:
     database_file: GeoLite2-City.mmdb
     field: source.ip
     target_field: source.geo
     properties:
       - continent_name
       - region_iso_code
       - city_name
       - country_iso_code
       - country_name
       - region_name
       - location
     ignore_missing: true
 - geoip:
     database_file: GeoLite2-City.mmdb
     field: destination.ip
     target_field: destination.geo
     properties:
       - continent_name
       - region_iso_code
       - city_name
       - country_iso_code
       - country_name
       - region_name
       - location

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 16, 2020, 3:00am UTC](https://discuss.elastic.co/t/filebeat/224017/6 "2020-04-16T03:00:37Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
