# Size of nested array is always 0

**URL:** <https://discuss.elastic.co/t/size-of-nested-array-is-always-0/202569>\
**Category:** Elasticsearch\
**Created:** [October 7, 2019, 4:30pm UTC](https://discuss.elastic.co/t/size-of-nested-array-is-always-0/202569 "2019-10-07T16:30:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![igushev](https://avatars.discourse-cdn.com/v4/letter/i/dbc845/32.png) [@igushev](https://discuss.elastic.co/u/igushev)\
**Post date:** [October 7, 2019, 4:30pm UTC](https://discuss.elastic.co/t/size-of-nested-array-is-always-0/202569/1 "2019-10-07T16:30:55Z")

</div>

Schema looks like this:

```
  "mappings": {
    "_doc": {
      "_all": {
        "enabled": false
      },
      "properties": {
        "category_boost": {
          "type": "nested",
          "properties" : {
            "category": {
              "type": "text",
              "index": false
            },
            "boost": {
              "type": "integer",
              "index": false
            }
          }
        }
      }
    }
  }

```

The document in elastic does have data:

```
"category_boost": [
    {
        "category": "A",
        "boost": 98
    },
    {
        "category": "B",
        "boost": 96
    },
    {
        "category": "C",
        "boost": 94
    },
],

```

Inside scoring function:

`for (int i=0; i<doc['"'category_boost.boost'"'].size(); ++i) { if (doc['"'category_boost.category'"'][i].value.equals(params.category)) { boost = doc['"'category_boost.boost'"'][i].value; } }`

Also tried `length` to get size of the array, but did help. Since it does not affect results, I tried to divide by `size()` and it throws division by zero error, so I conclude the size is 0.

**Overall problem** : have a map of category-\>boost which is dynamic and I cannot hardcode into schema. I tried type `object` with json object, but it turned out you cannot access those objects in scoring functions, therefore I went with arrays with defined types.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 9, 2019, 7:26am UTC](https://discuss.elastic.co/t/size-of-nested-array-is-always-0/202569/2 "2019-10-09T07:26:52Z")

</div>

Hey,

from a quick peek at your data structure, the array is `doc["category_boost"]` rather than `doc["category_boost.boost"]`.

Can you explain what you mean with dynamic in the map? Does it mean, it has different data types?

Also, have you taken a look at the nested datatype, as this might help you.

--Alex

---

<div class="post-metadata">

**Author:** ![igushev](https://avatars.discourse-cdn.com/v4/letter/i/dbc845/32.png) [@igushev](https://discuss.elastic.co/u/igushev)\
**Post date:** [October 9, 2019, 5:18pm UTC](https://discuss.elastic.co/t/size-of-nested-array-is-always-0/202569/3 "2019-10-09T17:18:20Z")

</div>

I mean that each deployment will have different categories, so I can't add to schema categoryA, categoryB, etc.

---

<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:** [November 6, 2019, 5:22pm UTC](https://discuss.elastic.co/t/size-of-nested-array-is-always-0/202569/4 "2019-11-06T17:22:26Z")

</div>

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