如何对elasticsearch中的数据进行人工操作

时间:2018-03-01 14:48:26

标签: elasticsearch elasticsearch-5 elasticsearch-net

我需要在特定节点类型上有平均cpuload。例如,如果我将nodetype指定为tpt,则应该提供所有cpuload的{​​{1}} nodetype的平均值。我尝试了不同的方法但是徒劳......

我在elasticsearch中的数据如下:

tpt

我的查询是

{
   "took" : 5,
   "timed_out" : false,
   "_shards" : {
     "total" : 5,
     "successful" : 5,
     "failed" : 0
   },
   "hits" : {
     "total" : 4,
     "max_score" : 1.0,
     "hits" : [
       {
         "_index" : "kpi",
         "_type" : "kpi",
         "_id" : "\u0003",
         "_score" : 1.0,
         "_source" : {
           "kpi" : {
             "CpuAverageLoad" : 13,
             "NodeId" : "kishan",
             "NodeType" : "Tpt",
             "State" : "online",
             "Static_limit" : 0
           }
         }
       },
       {
         "_index" : "kpi",
         "_type" : "kpi",
         "_id" : "\u0005",
         "_score" : 1.0,
         "_source" : {
           "kpi" : {
             "CpuAverageLoad" : 15,
             "NodeId" : "kishan1",
             "NodeType" : "tpt",
             "State" : "online",
             "Static_limit" : 0
           }
         }
       },
       {
         "_index" : "kpi",
         "_type" : "kpi",
         "_id" : "\u0004",
         "_score" : 1.0,
         "_source" : {
           "kpi" : {
             "MaxLbCapacity" : "700000",
             "NodeId" : "kishan2",
             "NodeType" : "bang",
             "OnlineCSCF" : [
               "001",
               "002"
             ],
             "State" : "Online",
             "TdbGroup" : 1,
             "TdGroup" : 0
           }
         }
       },
       {
         "_index" : "kpi",
         "_type" : "kpi",
         "_id" : "\u0002",
         "_score" : 1.0,
         "_source" : {
           "kpi" : {
             "MaxLbCapacity" : "700000",
             "NodeId" : "kishan3",
             "NodeType" : "bang",
             "OnlineCSCF" : [
               "001",
               "002"
             ],
             "State" : "Online",
             "TdLGroup" : 1,
             "TGroup" : 0
           }
         }
       }
     ]
   }
 }

但由于无法找到确切来源而下降。

curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d'
{
    "query": {
        "bool" : {
            "must" : {
                "script" : {
                    "script" : {
                        "source" : "kpi[CpuAverageLoad].value > params.param1",
                        "lang"   : "painless",
                        "params" : {
                            "param1" : 5
                        }
                    }
                }
            }
        }
    }
}'

0 个答案:

没有答案