elasticsearch - 在数字数组字段上聚合时Elasticsearch预期的行为

标签 elasticsearch

我有一个汇总查询,根据数值数组字段中的值将数据分类到直方图存储桶中。该数组几乎总是具有长度1,但是我不能保证。
在作为数组的字段上进行这样的装箱时,预期的行为是什么?

我知道,如果必须执行此查询,我们可能必须修改架构,但仍想了解 flex 在这里的表现。

示例文件:

    {
      "begin": "100",
      "total": 20,
      "fractions": [ 10 ]
    }

查询示例:
GET /index-2/_search
{
  "size": 10, 
  "aggs": {
    "buckets": {
      "histogram": {
        "field": "begin",
        "interval": 1000
      },
      "aggs": {
        "fractions": {
          "histogram": {
            "field": "fractions",
            "interval": 10
          }
        }
        "totals": {
          "histogram": {
            "field": "totals",
            "interval": 10
          }
        }
      }
    }
  }
}

在4到5百万个文档上运行此查询时,我没有任何错误。以下是示例响应片段:
"aggregations": {
  "buckets": {
    "buckets": [
    {
      "key": 0,
      "doc_count": 1235,
      "fractions": {
        "buckets": [
          {
            "key": 0,
            "doc_count": 402
          },
          {
            "key": 10,
            "doc_count": 176
          },

          ...

          {
            "key": 480,
            "doc_count": 0
          },
          {
            "key": 490,
            "doc_count": 1
          }
        ]
      },
      "totals": {
        "buckets": [
          {
            "key": 0,
            "doc_count": 271
          },
          {
            "key": 10,
            "doc_count": 117
          },

          ...

          {
            "key": 550,
            "doc_count": 0
          },
          {
            "key": 560,
            "doc_count": 1
          }
        ]
      }
    },
    ...

最佳答案

数组中的值将有助于创建该时间间隔的存储桶。如果与查询匹配的文档的fractions值为10, 50, 90, 100,并且其中一个文档的[10, 20, 150]fractions,则这些值将基本上增加构成存储桶“可用”值数组的术语列表。 fractions聚合将覆盖从10150的所有存储桶。

例如,像{"begin":100,"total":20,"fractions":[10,35,55]}之类的文档具有像"fractions": {"histogram": {"field": "fractions", interval": 5}}之类的聚合,将生成诸如

           "fractions": {
              "buckets": [
                 {
                    "key": 10,
                    "doc_count": 1
                 },
                 {
                    "key": 15,
                    "doc_count": 0
                 },
                 {
                    "key": 20,
                    "doc_count": 0
                 },
                 {
                    "key": 25,
                    "doc_count": 0
                 },
                 {
                    "key": 30,
                    "doc_count": 0
                 },
                 {
                    "key": 35,
                    "doc_count": 1
                 },
                 {
                    "key": 40,
                    "doc_count": 0
                 },
                 {
                    "key": 45,
                    "doc_count": 0
                 },
                 {
                    "key": 50,
                    "doc_count": 0
                 },
                 {
                    "key": 55,
                    "doc_count": 1
                 }
              ]
           }

基本上,值列表只是聚合集中的一组附加术语。

关于elasticsearch - 在数字数组字段上聚合时Elasticsearch预期的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38982037/

相关文章:

elasticsearch - 显示基巴纳的所有可用路线

elasticsearch - Logstash:使用Filebeat时如何从路径获取字段?

node.js - 如何在我的 Dockerfile 中添加 discovery.type=single-node

java - Elasticsearch |模板查询 | Java接口(interface)

elasticsearch - 如何通过 JSON 将查询设置为 Elasticsearch SearchRequest?

c# - 如何在Elasticsearch中匹配搜索查询中的单个单词

Elasticsearch 分片卡在初始化状态

elasticsearch - 是否可以在 logstash scripted_upsert 期间访问事件字段?

elasticsearch - Elasticsearch在删除索引时触发refresh_mappings

elasticsearch - Elasticsearch 2.x至5.x查询问题