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

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-count-elements-of-an-array-of-two-levels-array-of-arrays/323047>\
**Category:** Elasticsearch\
**Created:** [January 12, 2023, 5:02pm UTC](https://discuss.elastic.co/t/is-it-possible-to-count-elements-of-an-array-of-two-levels-array-of-arrays/323047 "2023-01-12T17:02:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcornejo](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jcornejo](https://discuss.elastic.co/u/jcornejo)\
**Post date:** [January 12, 2023, 5:02pm UTC](https://discuss.elastic.co/t/is-it-possible-to-count-elements-of-an-array-of-two-levels-array-of-arrays/323047/1 "2023-01-12T17:02:38Z")

</div>

I need to count the elements of the campaign\_promotions.promotion\_prices array

it's possible?

```auto
"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"
        }
      }
]

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [January 12, 2023, 8:07pm UTC](https://discuss.elastic.co/t/is-it-possible-to-count-elements-of-an-array-of-two-levels-array-of-arrays/323047/2 "2023-01-12T20:07:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jcornejo](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jcornejo](https://discuss.elastic.co/u/jcornejo)\
**Post date:** [January 12, 2023, 9:40pm UTC](https://discuss.elastic.co/t/is-it-possible-to-count-elements-of-an-array-of-two-levels-array-of-arrays/323047/3 "2023-01-12T21:40:46Z")

</div>

I need to know how many elements it contains

> result: 10

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 9, 2023, 9:41pm UTC](https://discuss.elastic.co/t/is-it-possible-to-count-elements-of-an-array-of-two-levels-array-of-arrays/323047/4 "2023-02-09T21:41:35Z")

</div>

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