Elasticsearch Search Query

Hi Team,
I have written a DSL Query as shown below:

GET metricbeat*/_search
{

"size": 0,
"aggs": {
"hosts": {
"terms": {
"field": "agent.hostname",
"size": "100",
"order": {
"memory": "desc"
}
},
"aggs": {
"memory": {
"avg": {
"field": "system.memory.actual.free"
}
}
}
}
}
}

Output:

{
  "took" : 2501,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "hosts" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "sdsprodeocmsec203core1",
          "doc_count" : 1455582,
          "memory" : {
            "value" : 6.308144997947844E10
          }
        },
        {
          "key" : "sdsprodeocmsec203core2",
          "doc_count" : 1454572,
          "memory" : {
            "value" : 6.2950276947254684E10
          }
        },
        {
          "key" : "sdsprodeocmprim203core1",
          "doc_count" : 3444008,
          "memory" : {
            "value" : 3.8508990372701004E10
          }
        },
        {
          "key" : "sdsprodeocmprim203core2",
          "doc_count" : 3434246,
          "memory" : {
            "value" : 3.660680294172565E10
          }
        },
        {
          "key" : "sdsprodeocmsec203eda2",
          "doc_count" : 1020806,
          "memory" : {
            "value" : 1.9688615705650944E10
          }
        },
        {
          "key" : "sdsprodeocmsec203eda3",
          "doc_count" : 1019856,
          "memory" : {
            "value" : 1.9612392458189976E10
          }
        },
        {
          "key" : "sdsprodeocmsec203eda1",
          "doc_count" : 987924,
          "memory" : {
            "value" : 1.8726296401312668E10
          }
        },
        {
          "key" : "sdsprodeocmsec203nso2",
          "doc_count" : 761952,
          "memory" : {
            "value" : 1.5937467810848082E10
          }
        },
        {
          "key" : "sdsprodeocmsec203nso1",
          "doc_count" : 918946,
          "memory" : {
            "value" : 1.5894312456272108E10
          }
        },
        {
          "key" : "sdsprodeocmsec203cwf1",
          "doc_count" : 768080,
          "memory" : {
            "value" : 1.5839803959610683E10
          }
        },
        {
          "key" : "sdsprodeocmsec203cwf2",
          "doc_count" : 836304,
          "memory" : {
            "value" : 1.582562529367544E10
          }
        },
        {
          "key" : "sdsprodeocmsec203rdb3",
          "doc_count" : 1008536,
          "memory" : {
            "value" : 1.515334139223609E10
          }
        },
        {
          "key" : "sdsprodeocmsec203rdb2",
          "doc_count" : 1010373,
          "memory" : {
            "value" : 1.5150414924147797E10
          }
        },
        {
          "key" : "sdsprodeocmsec203rdb1",
          "doc_count" : 1001926,
          "memory" : {
            "value" : 1.5133592761496319E10
          }
        },
        {
          "key" : "sdsprodeocmprim203rdb3",
          "doc_count" : 997401,
          "memory" : {
            "value" : 1.5037380659856907E10
          }
        },
        {
          "key" : "sdsprodeocmprim203rdb1",
          "doc_count" : 995977,
          "memory" : {
            "value" : 1.5033719006216696E10
          }
        },
        {
          "key" : "sdsprodeocmprim203rdb2",
          "doc_count" : 1029238,
          "memory" : {
            "value" : 1.4447070366370386E10
          }
        },
        {
          "key" : "sdsprodeocmprim203cwf2",
          "doc_count" : 954471,
          "memory" : {
            "value" : 1.4292904171316238E10
          }
        },
        {
          "key" : "sdsprodeocmprim203cwf1",
          "doc_count" : 988001,
          "memory" : {
            "value" : 1.3973256637985107E10
          }
        },
        {
          "key" : "sdsprodeocmprim203nso2",
          "doc_count" : 1218301,
          "memory" : {
            "value" : 1.3578007306804802E10
          }
        },
        {
          "key" : "sdsprodeocmprim203nso1",
          "doc_count" : 1272198,
          "memory" : {
            "value" : 1.3463136983814968E10
          }
        },
        {
          "key" : "sdsprodeocmprim203eda2",
          "doc_count" : 964614,
          "memory" : {
            "value" : 1.1065032527616201E10
          }
        },
        {
          "key" : "sdsprodeocmprim203eda3",
          "doc_count" : 932509,
          "memory" : {
            "value" : 1.0802071477926931E10
          }
        },
        {
          "key" : "sdsprodeocmprim203eda1",
          "doc_count" : 961280,
          "memory" : {
            "value" : 9.998644102230932E9
          }
        },
        {
          "key" : "sdsprodeocmprim203esa2",
          "doc_count" : 906592,
          "memory" : {
            "value" : 3.0499617755102468E9
          }
        },
        {
          "key" : "sdsprodeocmsec203esa2",
          "doc_count" : 671498,
          "memory" : {
            "value" : 3.027275237983846E9
          }
        },
        {
          "key" : "sdsprodeocmprim203esa1",
          "doc_count" : 910443,
          "memory" : {
            "value" : 3.0147089465706315E9
          }
        },
        {
          "key" : "sdsprodeocmsec203esa1",
          "doc_count" : 696551,
          "memory" : {
            "value" : 3.0085840084308147E9
          }
        }
      ]
    }
  }
}

Blockquote

I want to get the result of hostname and free memory value only from the json output. Can somebody help me to achieve the same as i need to get the values from the array.

Note: I have multiple hosts.

Please support.

//Ankita

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.