[英]Adding new custom field in kibana
Is there a way to add a new field to all the documents in a index in kibana?有没有办法在 kibana 的索引中的所有文档中添加一个新字段? For example, lets assume, i have the age of all the users in my elastic kibana.例如,假设我有弹性 kibana 中所有用户的年龄。 And i want to separate them into two categories as Below 50 and Above 50 .我想将它们分为50 以下和 50 以上两类。 So if there is a user who is 23 years of age, he should have a category value as Below 50 .所以如果有一个23 岁的用户,他的类别值应该是低于 50 。
Yes, you can.是的你可以。 What you want is update-by-query and painless-scripts .你想要的是update-by-query和painless-scripts 。
They will give you flexibility to do something of this sort他们会给你灵活性来做这种事情
POST /users/string/_update_by_query
{
"script": "ctx._source.category = ctx._source.age > 50 ? "Above 50" : "Below 50"
}
I'd like to add another option to the one offered by @dravit.我想为@dravit 提供的选项添加另一个选项。 If you don't want to modify your documents, and you only need that extra field to run analysis in Kibana, you can add a scripted field to your index pattern, so that the category
value is calculated at query time.如果您不想修改文档,并且只需要该额外字段来在 Kibana 中运行分析,则可以将脚本字段添加到索引模式中,以便在查询时计算category
值。
Ref: https://www.elastic.co/guide/en/kibana/current/scripted-fields.html参考: https://www.elastic.co/guide/en/kibana/current/scripted-fields.html
The script for your scripted field would be something as easy as您的脚本字段的脚本将很简单
doc['age'].value > 50 ? "Above 50" : "Below 50"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.