表达式中使用的字段[]在映射中不存在

Pau*_*eux 5 elasticsearch kibana elastic-stack

我尝试填充的功能是在kibana中创建一个度量标准,显示"未经验证"的用户数.我发送用户注册时发送的日志,然后验证用户验证时的日志.

所以我想要的数量是注册数量和验证数量之间的差异.

在kibana我不能做这样的数学运算,所以我找到了一个解决方法:我添加了一个名为"unvalidated"的"脚本字段",当用户注册时等于1,当用户验证他的帐户时等于-1."未经验证"字段的总和应该是未经验证的用户的数量.

这是我在脚本字段中定义的脚本: doc['ctxt_code'].value == 1 ? 1 : doc['ctxt_code'].value == 2 ? -1 : 0

有:

  • ctxt_code 1作为寄存器日志

  • ctxt_code 2作为验证日志

当我的所有日​​志都有"ctxt_code"时,此设置很有效,但是当没有此字段的日志被推送时,kibana会抛出以下错误:

Field [ctxt_code] used in expression does not exist in mappings kibana错误

我无法理解这个错误,因为kibana说:

If a field is sparse (only some documents contain a value), documents missing the field will have a value of 0

情况就是这样.

有人有线索吗?

Jos*_*oco 2

没有该字段的日志是可以的ctxt_code...但是您必须在索引中拥有该字段的映射。我发现您正在使用 查询多个索引logstash-*,因此您可能会遇到没有该索引的索引。

您可以在所有索引中包含您的字段的映射。只需进入Sense并使用它:

PUT logstash-*/_mappings/[your_mapping_name]
{
  "properties": {
    "ctxt_code": {
      "type": "short",           // or any other numeric type, including dates
      "index": "not_analyzed"    // Only works for non-analyzed fields.
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

如果您愿意,可以从命令行执行此操作:CURL -XPUT 'http://[elastic_server]/logstash-*/_mappings/[your_mapping_name]' -d '{ ... same JSON ... }'