Is it possible to count elements of an array of two levels? array of arrays

I need to count the elements of the campaign_promotions.promotion_prices array

it's possible?

"hits" : [
      {
        "_index" : "dev_scrap_campaigns",
        "_type" : "_doc",
        "_id" : "2t0k7oQBF4RU85fFCPX_",
        "_score" : 1.0,
        "_source" : {
          "g_shop_name" : "shoping_test",
          "campaign_name" : "test ",
          "campaign_created_at" : "2022-12-07T19:51:21.133Z",
          "campaign_status" : 1,
          "campaign_promotions" : [
            {
              "promotion_date_end" : "2022-12-26T00:00:00.000Z",
              "promotion_type" : 1,
              "_promotion_prices_monitoring_count" : 10,
              "promotion_origin" : 0,
              "promotion_status" : 1,
              "promotion_prices" : [
                {
                  "promotion_date_end" : "2022-12-26T00:00:00.000Z",
                  "promotion_type" : 1,
                  "promotion_price_base_unit_measure" : "UN",
                  "promotion_origin" : 0,
                  "promotion_price_cc_price" : 0.25,
                  "promotion_date_start" : "2022-11-29T00:00:00.000Z",
                  "promotion_price_name" : "PACK SELECC 4 TURRONES EL ALMENDRO 370G"
                },
                {
                  "promotion_date_end" : "2022-12-26T00:00:00.000Z",
                  "promotion_type" : 1,
                  "promotion_price_base_unit_measure" : "UN",
                  "promotion_origin" : 0,
                  "promotion_price_cc_price" : 0.25,
                  "promotion_date_start" : "2022-11-29T00:00:00.000Z",
                  "promotion_price_name" : "TURRON DURO EL ALMENDRO 150G",
                  "promotion_price_flags" : [ ],
                  "promotion_name" : "TODOS LOS TURRONES ESPAÑOLES EL ALMENDRO"
                }
              ],
              "promotion_name" : "TODOS LOS TURRONES ESPAÑOLES EL ALMENDRO",
              "_promotion_prices_process_done" : true,
              "_promotion_prices_waiting_count" : 0,
              "promotion_date_start" : "2022-11-29T00:00:00.000Z",
              "_promotion_prices_error_count" : 6,
              "promotion_token" : "xxxxxxx"
            }
          ],
          "campaign_monitoring_status" : "finished",
          "campaign_uses_promotions" : true,
          "campaign_monitoring_updated_at" : "2022-12-07T19:51:51.791Z"
        }
      }
]

I believe it is possible, using aggregation or scripts, but it depends on which output you want.

I need to know how many elements it contains

result: 10

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