elasticsearch - Kibana 脚本化字段循环遍历数组

标签 elasticsearch kibana metricbeat

我正在尝试使用 metricbeat http 模块来监控 F5 池。

我向 f5 api 发出请求并带回 json,该 json 保存到 kibana。但 json 包含一个池成员数组,我想计算已增加的数量。

建议似乎是这可以通过脚本字段来完成。但是,我无法获取脚本来检索数组。例如

doc['http.f5pools.items.monitor'].value.length()

返回预览结果,并添加相同的“附加字段”以进行比较:

[
 {
  "_id": "rT7wdGsBXQSGm_pQoH6Y",
  "http": {
   "f5pools": {
    "items": [
     {
      "monitor": "default"
     },
     {
      "monitor": "default"
     }
    ]
   }
  },
  "pool.MemberCount": [
   7
  ]
 },

如果我尝试

doc['http.f5pools.items']

或者类似的,我只是收到一个错误:

"reason": "No field found for [http.f5pools.items] in mapping with types []"

谷歌搜索表明文档结构不包含数组?

  1. 是否可以创建一个可以访问该组值的脚本字段? ie 是我的代码或我索引数据的方式错误。
  2. 如果没有,metricbeats 中是否有替代方法?我不想创建一个全新的 api 来进行计算并添加单独的字段

--更新。

奇怪的是,数组中的数值似乎确实返回了预期的结果。即。

doc['http.f5pools.items.ratio']

返回

 {
  "_id": "BT6WdWsBXQSGm_pQBbCa",
  "pool.MemberCount": [
   1,
   1
  ]
 },

--更新2

好的,所以如果字段中的字符串具有不同的值,那么您将获得所有值。如果它们相同,您只需得到一个。什么鬼?

最佳答案

我正在添加另一个答案,而不是删除之前的答案,这不是实际的问题,但仍然可能对其他人有帮助。

我在 same documentation 中找到了提示:

Doc values are a columnar field value store

进一步谷歌搜索后,我发现了这个 Doc Value Intro这表明文档值本质上是“非倒排索引”,对于排序等操作很有用;我的假设是,在排序时,您本质上不希望重复相同的值,因此它们使用的数据结构会删除这些重复项。这仍然没有回答为什么它对字符串和数字的作用不同。数字被保留,但字符串被过滤为唯一。

This “uninverted” structure is often called a “column-store” in other systems. Essentially, it stores all the values for a single field together in a single column of data, which makes it very efficient for operations like sorting.

In Elasticsearch, this column-store is known as doc values, and is enabled by default. Doc values are created at index-time: when a field is indexed, Elasticsearch adds the tokens to the inverted index for search. But it also extracts the terms and adds them to the columnar doc values.

更多deep-dive into doc values revealed it a compression technique这实际上消除了重复的值,以实现高效且内存友好的操作。

上面的链接上给出了一个注释,它回答了问题:

You may be thinking "Well that’s great for numbers, but what about strings?" Strings are encoded similarly, with the help of an ordinal table. The strings are de-duplicated and sorted into a table, assigned an ID, and then those ID’s are used as numeric doc values. Which means strings enjoy many of the same compression benefits that numerics do.

The ordinal table itself has some compression tricks, such as using fixed, variable or prefix-encoded strings.

另外,如果您不想要这种行为,那么您可以 disable doc-values

关于elasticsearch - Kibana 脚本化字段循环遍历数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56688792/

相关文章:

elasticsearch - Elasticsearch截断查询中的字符串字段

elasticsearch - ElasticSearch,行ACL

json - 如何在Elasticsearch中通过两个子句过滤数据?

elasticsearch - Elasticsearch中的观察者以提高CPU使用率

java - 如何向 Spring Boot 项目添加多个 Elasticsearch 连接?

Cloudfoundary 上的 Elasticsearch

elasticsearch - Elasticsearch部分匹配顺序

elasticsearch - .keyword已添加到Kibana中的所有字段以进行Elasticsearch可视化

elasticsearch - 我如何获得metricbeat向Kibana报告标准化的CPU百分比

linux - logstash 不读取 Metricbeat 数据