Iterating over ES Aggregation query using JAVA API

I have following query which is queried using JAVA, but I don't know how to iterate over "permalink_url" field ?
Field response for permalink_url looks like =>

    "permalink_url": {
            "hits": {
              "total": 1,
              "max_score": 10.197851,
              "hits": [
                {
                  "_index": "instagram_2018",
                  "_type": "post",
                  "_id": "145672123558_101543454556995",
                  "_score": 10.1934331,
                  "_source": {
                    "permalink_url": "https://www.instagram.com/p/123456789/"
                  }
                }
              ]
            }
          }

Query =>

GET instagram_2018/_search?pretty
{
  "size" : 0,
  "timeout" : 40000,
  "query" : {
    "bool" : {
      "must" : [ {
        "bool" : {
          "should" : {
            "bool" : {
              "must" : {
                "bool" : {
                  "must" : {
                    "bool" : {
                      "should" : [ {
                        "match" : {
                          "ABC.text" : {
                            "query" : "Some text",
                            "type" : "phrase"
                          }
                        }
                      }
                      } ]
                    }
                  }
                }
              }
            }
          }
        }
      }, {
        "range" : {
          "created_time" : {
            "from" : "2018-02-01T11:16:00.000Z",
            "to" : "2018-02-07T19:16:00.000Z",
            "include_lower" : true,
            "include_upper" : false
          }
        }
      }, {
        "terms" : {
          "from.name" : [ "SpaceX" ]
        }
      }]
    }
  },
  "aggregations" : {
    "post_type_filter" : {
      "filter" : {
        "term" : {
          "_type" : "post"
        }
      },
      "aggregations" : {
        "gender" : {
          "terms" : {
            "field" : "ABC.gender"
          }
        },
        "permalink_url" : {
          "top_hits": {
            "_source": {"includes":["permalink_url"],"excludes": [""]}
          }
        },
        "reaction_like" : {
          "sum" : {
            "field" : "ABC.reaction_like_count"
          }
        },
        "unique_users" : {
          "cardinality" : {
            "field" : "from.name"
          }
        }
      }
    }
  }
}

I tried following but it doesn't work ->
((TopHits) aggregations.get("permalink_url")).getName()
((TopHits) aggregations.get("permalink_url")).getHits().toString()

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