# Which structure of nested field is more efficient?

**URL:** <https://discuss.elastic.co/t/which-structure-of-nested-field-is-more-efficient/286096>\
**Category:** Elasticsearch\
**Created:** [October 7, 2021, 6:58am UTC](https://discuss.elastic.co/t/which-structure-of-nested-field-is-more-efficient/286096 "2021-10-07T06:58:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![taichi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/taichi/32/46431_2.png) [@taichi](https://discuss.elastic.co/u/taichi)\
**Post date:** [October 7, 2021, 6:58am UTC](https://discuss.elastic.co/t/which-structure-of-nested-field-is-more-efficient/286096/1 "2021-10-07T06:58:39Z")

</div>

I'm using Elasticsearch 7.10 and I have an ES index which includes about 3M documents.  
I am going to add nested field (I call it `items`) which has fields as below:

- store\_id (long)
- big\_category\_id (integer / there are only 5 categories now)
- timestamp (date)

Each document has about 5 items. We have to update items data everyday.

I have two plans.

1. Add a single nested field and put all items to it with big\_category\_id as below.  
We have to specify big\_category\_id in the query.

```auto
"items": [
  {
    "store_id": 1,
    "big_category_id": 1,
    "timestamp": "2021-10-01 00:00:00"
  },
  {
    "store_id": 1,
    "big_category_id": 2,
    "timestamp": "2021-10-01 00:00:00"
  },
  ...
]

```

1. Add nested fields for each `big_category_id` as below:  
We don't need big\_category\_id in the query.

```auto
"items_of_category_1": [
  {
    "store_id": 1,
    "timestamp": "2021-10-01 00:00:00"
  },
  {
    "store_id": 2,
    "timestamp": "2021-10-01 00:00:00"
  },
  ...
],
"items_of_category_2": [
  {
    "store_id": 1,
    "timestamp": "2021-10-01 00:00:00"
  }
],
...

```

I think the first plan is better because of its simplicity, but I don't know which is more efficient (especially when querying and fetching data) in terms of the internal structure of Elasticsearch.  
Which do you think is better?

---

<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 4, 2021, 6:58am UTC](https://discuss.elastic.co/t/which-structure-of-nested-field-is-more-efficient/286096/2 "2021-11-04T06:58:44Z")

</div>

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