はじめに
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でrouting
IDを追加する必要があります。
if [type] == "child_actions" {
elasticsearch {
hosts => [ "localhost:9200" ]
index => "logstash-index-name"
routing => "%{parent_id}" <-- here!
}
}
これで、すべての子ドキュメントに "join_field "がネストされたフィールドとして追加されるようになりました。
詳しくは別途また記事を書きます。
Elasticsearch Reference [7.9] » Mapping » Field data types » Join field type