我一直在使用Logstash将一些索引从自托管的Elasticsearch迁移到AmazonElasticSearch。在迁移文档时,我们需要根据一些逻辑来更改索引中的字段名称。
我们的Logstash配置文件
input {
elasticsearch {
hosts => ["https://staing-example.com:443"]
user => "userName"
password => "password"
index => "testingindex"
size => 100
scroll => "1m"
}
}
filter {
}
output {
amazon_es {
hosts => ["https://example.us-east-1.es.amazonaws.com:443"]
region => "us-east-1"
aws_access_key_id => "access_key_id"
aws_secret_access_key => "access_key_id"
index => "testingindex"
}
stdout{
codec => rubydebug
}
}
这是我们自托管的 Elasticsearch 中的testingIndex的文档之一
{
"uniqueIdentifier" => "e32d331b-ce5f-45c8-beca-b729707fca48",
"createdDate" => 1527592562743,
"interactionInfo" => [
{
"value" => "Hello this is testing",
"title" => "msg",
"interactionInfoId" => "8c091cb9-e51b-42f2-acad-79ad1fe685d8"
},
{
**"value"** => """"{"edited":false,"imgSrc":"asdfadf/soruce","cont":"Collaborated in <b class=\"mention\" gid=\"4UIZjuFzMXiu2Ege6cF3R4q8dwaKb9pE\">@2222222</b> ","chatMessageObjStr":"Btester has quoted your feed","userLogin":"test.comal@google.co","userId":"tester123"}"""",
"title" => "msgMeta",
"interactionInfoId" => "f6c7203b-2bde-4cc9-a85e-08567f082af3"
}
],
"componentId" => "compId",
"status" => [
"delivered"
]
},
"accountId" => "test123",
"applicationId" => "appId"
}
这就是我们将文档迁移到我们的AmazonElasticSearch时的期望
{
"uniqueIdentifier" => "e32d331b-ce5f-45c8-beca-b729707fca48",
"createdDate" => 1527592562743,
"interactionInfo" => [
{
"value" => "Hello this is testing",
"title" => "msg",
"interactionInfoId" => "8c091cb9-e51b-42f2-acad-79ad1fe685d8"
},
{
**"value-keyword"** => """"{"edited":false,"imgSrc":"asdfadf/soruce","cont":"Collaborated in <b class=\"mention\" gid=\"4UIZjuFzMXiu2Ege6cF3R4q8dwaKb9pE\">@2222222</b> ","chatMessageObjStr":"Btester has quoted your feed","userLogin":"test.comal@google.co","userId":"tester123"}"""",
"title" => "msgMeta",
"interactionInfoId" => "f6c7203b-2bde-4cc9-a85e-08567f082af3"
}
],
"componentId" => "compId",
"status" => [
"delivered"
]
},
"accountId" => "test123",
"applicationId" => "appId"
}
我们需要的是在任何找到JSON格式的地方,将“值” 字段更改为“值-关键字” 。 Logstash中是否有其他过滤器可以实现此目的
最佳答案
如Logstash网站中所述:
https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-rename
您可以使用重命名功能使用mutate过滤器。
例如:
filter {
mutate {
replace => { "old-field" => "new-field" }
}
}
对于嵌套字段,您可以只传递字段的路径:
filter {
mutate {
replace => { "[interactionInfo][value]" => "[interactionInfo][value-keyword]" }
}
}
关于elasticsearch - Logstash:是否有一种方法可以在迁移时更改文档中的某些属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58487292/