Kibana metric visualization - Get Inner hits count

Here's my code to get inner hits count.

        GET my_index/_search
        {
          "_source": [
            "inner_hits"
          ],
          "query": {
            "nested": {
              "path": "someNestedKey",
              "query": {
                "bool": {
                  "must": [
                    {
                      "exists": {
                        "field": "someNestedKey.key1"
                      }
                    }
                  ]
                }
              },
              "inner_hits": {}
            }
          }
        }

This gives me the following response.

    {
      "took" : 2,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 2,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "my_index",
            "_type" : "_doc",
            "_id" : "someid",
            "_score" : 1.0,
            "_source" : { },
            "inner_hits" : {
              "my_nested_field" : {
                "hits" : {
                  "total" : {
                    **"value" : 5,**
                    "relation" : "eq"
                  },
                  "max_score" : 1.0,
                  "hits" : [{Removed the data}
                  ]
                }
              }
            }
          },
          {
            "_index" : "my_index",
            "_type" : "_doc",
            "_id" : "someid",
            "_score" : 1.0,
            "_source" : { },
            "inner_hits" : {
              "my_nested_field" : {
                "hits" : {
                  "total" : {
                    **"value" : 4,**
                    "relation" : "eq"
                  },
                  "max_score" : 1.0,
                  "hits" : [
                   {Removed the data}
                  ]
                }
              }
            }
          }
        ]
      }
    }

If you check the bold highlighted part, I basically need to get the total count that is 5+4 = 9 and show it inside Kibana's metric visualisation. I am not quite sure how to do it?

The metric visualization doesn't support nested data like this. You probably should use Vega because that would let you run the query directly using the query DSL

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