# Object or Nested performance and use?

**URL:** <https://discuss.elastic.co/t/object-or-nested-performance-and-use/214552>\
**Category:** Elasticsearch\
**Created:** [January 10, 2020, 7:35am UTC](https://discuss.elastic.co/t/object-or-nested-performance-and-use/214552 "2020-01-10T07:35:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![KrishK](https://avatars.discourse-cdn.com/v4/letter/k/c89c15/32.png) [@KrishK](https://discuss.elastic.co/u/KrishK)\
**Post date:** [January 10, 2020, 7:35am UTC](https://discuss.elastic.co/t/object-or-nested-performance-and-use/214552/1 "2020-01-10T07:35:53Z")

</div>

Hi Support,

I have data as below.

```
DELETE test_nested_vs_object
PUT test_nested_vs_object
{
  "mappings": {
    "properties": {
      "id": {
        "type":"long"
      },
      "title" :
      {
        "type": "text" 
      },
      "categories": {
        "type": "object",
        "properties": {
          "d": {
            "type": "short"
          }
        }
      }
    }
  }
}

POST test_nested_vs_object/_doc
{
  "id" : 1,
  "title" : "An article title 1",
  "categories" : [{"d":1}]
}
POST test_nested_vs_object/_doc
{
  "id" : 2,
  "title" : "An article title 2 ",
  "categories" : [{"d":1},{"d":2}]
}

POST _sql
{
  "query": "select * from test_nested_vs_object where categories.d = 2 "
}

```

Which data type is preferable for above data?

if we use object / Nested on huge index,which will give better performance on sql query?

How we can use/fetch object field using elasticsearch SQL query on object type field?

Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2020, 7:54am UTC](https://discuss.elastic.co/t/object-or-nested-performance-and-use/214552/2 "2020-01-10T07:54:47Z")

</div>

With the example you gave (only one subfield `d` in the `categories` nested object), it's better to use `object` as `nested` does not bring any value here.

If you actual data is more complex than that, then that's another story.

---

<div class="post-metadata">

**Author:** ![KrishK](https://avatars.discourse-cdn.com/v4/letter/k/c89c15/32.png) [@KrishK](https://discuss.elastic.co/u/KrishK)\
**Post date:** [January 10, 2020, 7:55am UTC](https://discuss.elastic.co/t/object-or-nested-performance-and-use/214552/3 "2020-01-10T07:55:54Z")

</div>

> [@dadoonet](#):
>
> nly one subfield `d` in the `categories` nested object

Yes, Only one subfield `d` in the `categories` nested object.

Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2020, 7:58am UTC](https://discuss.elastic.co/t/object-or-nested-performance-and-use/214552/4 "2020-01-10T07:58:01Z")

</div>

So don't use `nested`.

---

<div class="post-metadata">

**Author:** ![KrishK](https://avatars.discourse-cdn.com/v4/letter/k/c89c15/32.png) [@KrishK](https://discuss.elastic.co/u/KrishK)\
**Post date:** [January 10, 2020, 11:21am UTC](https://discuss.elastic.co/t/object-or-nested-performance-and-use/214552/5 "2020-01-10T11:21:51Z")

</div>

Thanks David

---

<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 7, 2020, 11:22am UTC](https://discuss.elastic.co/t/object-or-nested-performance-and-use/214552/6 "2020-02-07T11:22:11Z")

</div>

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