简体   繁体   English

使用 Logstash 过滤 MongoDB 文档的深层字段

[英]Filter MongoDB document's deep fields using Logstash

I am trying to rename some deep fields from my MongoDB document before uploading them to Elastic using Logstash.在使用 Logstash 将它们上传到 Elastic 之前,我试图重命名我的 MongoDB 文档中的一些深层字段。

For example: my MongoDB document looks like this:例如:我的 MongoDB 文档如下所示:

name: "firstDoc",
infoArray: 
[
   {infoName: "i", elements:{e1: "e1", e2: "e2"}}, 
   {infoName: "j", elements:{e3: "e3", e4: "e4"}}
]

I was able to access the "name" field in logstash like this:我能够像这样访问logstash中的“名称”字段:

mutate { add_field => {"[otherDoc][name]" => "%{[document][name]}"} }

But I am not able to access the fields in infoArray, I have tried the rename:但是我无法访问 infoArray 中的字段,我尝试了重命名:

mutate { rename => {"[document][infoArray][elements][e1]" => "[otherDoc][e1]"} }

I have also tried by adding it as a new field:我还尝试将其添加为新字段:

mutate { add_field => {"[otherDoc][e1]" => "%{[document][infoArray][elements][e1]}"} }

But still not working.但仍然无法正常工作。

Is there any way to access deep fields?有没有办法进入深场?

I have found the solution, as follows:我找到了解决方案,如下所示:

mutate { rename => {"[document][infoArray][0][elements][e1]" => "[otherDoc][e1]"} }

or或者

mutate { add_field => {"[otherDoc][e1]" => "%{[document][infoArray][0][elements][e1]}"} }

The index of infoArray should be specified in Logstash. infoArray 的索引应该在 Logstash 中指定。

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

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