简体   繁体   English

Elasticsearch 查询未返回求和字段的总值

[英]Elasticsearch query is not returning a total value of a summed field

I have the following elasticsearch query.我有以下 elasticsearch 查询。 It's being executed as part of AWS Amplify serverless backend.它作为 AWS Amplify 无服务器后端的一部分执行。

const elasticBody = {
    ...defaultBody,
    aggs: {
      points: {
        date_histogram: {
          field: "createdAt",
          interval: "day",
        },
        aggs: {
          points: {
            sum: {
              field: "points",
            },
          },
        },
      },
      total: {
        sum: {
          field: "points",
        },
      },
    },
  };

  const data = await search(index, elasticBody);

I get the following response, which is most of what I'm attempting to get, however, the 'total' value, in the lower portion of the query is not yielding a result.我得到以下响应,这是我试图获得的大部分内容,但是,查询下部的“总计”值没有产生结果。

I've been poring over the Elasticsearch documentation but I'm unable to find a solution.我一直在仔细研究 Elasticsearch 文档,但找不到解决方案。

在此处输入图像描述

I was expecting the following structure in the response.我期待响应中的以下结构。

count: x,
data: [{...}],

I was expecting the count to be the summed value of all the points within the returned data set.我期望计数是返回数据集中所有点的总和值。

You need to use Sum Bucket Aggregation to get total sum of return bucket response.您需要使用Sum Bucket Aggregation来获取返回存储桶响应的总和。 Please check below query:请检查以下查询:

"aggs": {
    "points": {
      "date_histogram": {
        "field": "createdAt",
        "interval": "day"
      },
      "aggs": {
        "points": {
          "sum": {
            "field": "points"
          }
        }
      }
    },
    "total":{
      "sum_bucket": {
        "buckets_path": "points>points"
      }
    }
  }

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

相关问题 从字段名称返回一个查询,其列作为特定类别的 COUNT - Returning a query with columns as COUNT of a specific category from a field name DynamoDB 查询日期字段在过滤器中返回非日期行 - DynamoDB Query Date Field returning non date rows in Filter Firebase 按特定字段值查询 - Firebase query by specific field value Firestore 通过数组的字段值进行查询 - Firestore to query by an array's field value Firestore 规则验证查询字段值 - Firestore rules validate query field value AWS Elasticsearch 发布了错误的总请求指标 - AWS Elasticsearch publishing wrong total request metric FirestoreService collectionStream 不返回值 - FirestoreService collectionStream not returning value Reactnative:查询和过滤 Firestore 数据库并将单个返回的文档字段值保存在 const/var 中 - Reactnative: Query and Filter Firestore Database and save a single returned document field value in a const/var 想要使用大查询 CONTAINS_SUBSTR 搜索存在于另一个字段中的字段值 - Want to search a field value present in another field using big query CONTAINS_SUBSTR 根据月份的日期在 Firebase 中保留文档字段的总计 - keeping a running total of documents field in Firebase based upon the day of month
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM