首页 > 解决方案 > 我的弹性平均查询错误 - 格式错误

问题描述

我得到了一个原因”:“[查询] 查询格式错误,查询名称后没有 start_object”错误,不知道为什么。

该查询旨在获取两个日期字段之间的差异并计算所有结果的平均值,我相信这应该有效,但可能无效。

任何帮助将不胜感激。

我在弹性版本 5.6.12

查询如下:

POST index_my.test/_search
{
  "size":10,
   "query": {
      "bool": {
      "must": [
        {
            "query": 
              "match_all": {}
          }
        }
      ]
    }
         "filter": {
            "and": [
               {
                  "exists": {
                     "field": "activity.timeline.found"
                  }
               }
               {
                  "exists": {
                     "field": "activity.timeline.sent"
                  }
               }
            ]
         },
         "aggs": {
      "avg_timedifference": {
         "avg": {
            "script" : "Math.ceil(doc['activity.timeline.found'].value - doc['activity.timeline.sent'].value)"
         }
      }
   }
}

标签: elasticsearchkibana

解决方案


您在“过滤器”之前忘记了逗号。尝试这个:

POST index_my.test/_search
{
  "size":10,
   "query": {
      "bool": {
      "must": [
        {
            "query": 
              "match_all": {}
          }
        }
      ]
    },
         "filter": {
            "and": [
               {
                  "exists": {
                     "field": "activity.timeline.found"
                  }
               }
               {
                  "exists": {
                     "field": "activity.timeline.sent"
                  }
               }
            ]
         },
         "aggs": {
      "avg_timedifference": {
         "avg": {
            "script" : "Math.ceil(doc['activity.timeline.found'].value - doc['activity.timeline.sent'].value)"
         }
      }
   }
}

推荐阅读