Object or Nested performance and use?

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

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.

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

Thanks

So don't use nested.

Thanks David

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