LoginSignup
1
1

More than 3 years have passed since last update.

Elasticsearch > Logstash > 親子関係データをLogstashで格納

Last updated at Posted at 2020-10-26

はじめに

Join field typeの導入に伴い、親子のリレーションシップが新しい形式に更新されました。
Logstashを使用して、親と子の結合に使用されるフィールドを指定する方法をメモします。

本稿はほぼ以下の意訳です。
How to create a parent using the new join type with logstash - Elastic Stack / Logstash - Discuss the Elastic Stack

詳しくは別途また記事を書く予定。

マッピング追加

Join field typeを作成するためIndexにマッピングを設定します。

PUT logstash-index-name
{
  "mappings": {
    "doc": {
      "properties": {
        "join_field": { 
          "type": "join",
          "relations": {
            "customer": "actions"
          }
        }
      }
    }
  }
}

Logstashでの設定追加

Logstash経由で親を追加することができます。
filterに以下を追加します。

mutate {
    add_field => { "join_field" => "customer" }         
}

子の設定では以下のように追加します。
パイプラインは親と子で分けた方がよさそうです

mutate {
    add_field => {"[join_field][name]" => "actions"}
    add_field => {"[join_field][parent]" => "%{parent_id}"}
}

子の設定の場合には
また、LogstashのOutputでroutingIDを追加する必要があります。

if [type] == "child_actions" {      
    elasticsearch {
        hosts => [ "localhost:9200" ]
        index => "logstash-index-name"
        routing => "%{parent_id}"  <-- here!
    }       
}

これで、すべての子ドキュメントに "join_field "がネストされたフィールドとして追加されるようになりました。

詳しくは別途また記事を書きます。

参考
How to create a parent using the new join type with logstash - Elastic Stack / Logstash - Discuss the Elastic Stack

Elasticsearch Reference [7.9] » Mapping » Field data types » Join field type

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1