移动聚合ElasticSearch

时间:2017-06-25 08:00:22

标签: curl elasticsearch elasticsearch-aggregation

G'day所有我一直试图破解为我的应用程序运行聚合并运行。

以下是我的文档对指标的看法。

"_index" : "metrics-2017-06-23",
"_type" : "metric",
 "_id" : "AVzUTWSCHd9DG10LCpmo",
"_score" : 0.0,
    "_source" : {
  "organisation" : "Organisation",
  "deployments" : [
    {
      "deployment_name" : "tqwerty",
      "instances" : [
        {
          "instance_name" : "7962c130ae1247229ee67aa534172f77",
          "object" : "fff",
          "version" : "adacb76ebd21",
          "cpu" : [
            {
              "time" : 1498174600,
              "value" : 10000
            }
          ],
          "disk_read" : [
            {
              "time" : 1498174600,
              "value" : 430
            }
          ],
          "disk_write" : [
            {
              "time" : 1498174600,
              "value" : 0
            }
          ],
          "net_read" : [
            {
              "time" : 1498174600,
              "value" : 0
            }
          ],
          "net_write" : [
            {
              "time" : 1498174600,
              "value" : 0
            }
          ]
        }
      ]
    }
  ]
}
}
]

我已将Curl请求下载到它工作的位置并隔离我想要的部署。但它只是没有表现出我的感动力。我不确定为什么我在文档上一字不漏地跟着。

curl -XPOST '10.0.0.34:9200/_search?pretty' -H 'Content-Type: application/json' -d'
{
"size": 20,
"query": { 
  "bool": { 
   "must": [
  { "match": { "organisation":   "Organisation"        }},
 { "match":  { "deployments.deployment_name": "tqwerty" }}
   ]
}
},
    "aggs": {
    "my_date_histo":{                
    "date_histogram":{
        "field":"deployments.instances.cpu.time",
        "interval":"30s"
       },
        "aggs":{
            "the_sum":{
            "sum":{ "field": "deployments.instances.cpu.value" } 
            },
            "the_movavg":{
            "moving_avg":{ "buckets_path": "the_sum" } 
        }
    }
}
}
}
 '

卷曲请求运行正常,但没有显示移动的agg确实显示总和,但它与数据匹配。

谢谢,

2 个答案:

答案 0 :(得分:2)

以下是我在评论中所说的内容 -

 curl -XPOST 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'
     {
       "size": 0,
       "query": { 
              "bool": { 
                   "must": [
                         { "match": { "organisation":   "Organisation"}},
                         { "match":  { "deployments.deployment_name": "tqwerty" }}
                   ]
                  }
               },
       "aggs": {
                "my_date_histo":{                
                   "date_histogram":{
                      "field":"deployments.instances.cpu.time",
                      "interval":"30s"
              },
                 "aggs":{
                 "the_sum":{
                 "sum":{ "field": "deployments.instances.cpu.value" } 
                },
                 "the_movavg":{
                      "moving_avg":{ "buckets_path": "the_sum" } 
              }
          }
      }
   }
}

结论:将尺寸更改为0

答案 1 :(得分:1)

这似乎解决了我的问题。这是令人惊讶的,因为它前几天没有...如果有其他人遇到这个尝试汤姆说的话,希望它会为你工作。