# Are Elasticsearch object properties really just flat properties with a namespace?

**URL:** <https://discuss.elastic.co/t/are-elasticsearch-object-properties-really-just-flat-properties-with-a-namespace/299054>\
**Category:** Elasticsearch\
**Created:** [March 8, 2022, 8:18am UTC](https://discuss.elastic.co/t/are-elasticsearch-object-properties-really-just-flat-properties-with-a-namespace/299054 "2022-03-08T08:18:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Krueger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robert_krueger/32/99210_2.png) [@Robert\_Krueger](https://discuss.elastic.co/u/Robert_Krueger)\
**Post date:** [March 8, 2022, 8:18am UTC](https://discuss.elastic.co/t/are-elasticsearch-object-properties-really-just-flat-properties-with-a-namespace/299054/1 "2022-03-08T08:18:22Z")

</div>

In the Elasticsearch docs ([Object field type | Elasticsearch Guide [8.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/object.html)) it is stated that object properties internally are essentially just flat properties with a namespace. However when I do this:

```auto
    POST storage-index/_doc
    {
      "person": {
        "lastName":"Miller" 
      },
      "person.lastName":"Smith"
    }

```

The index contains this:

```auto
        "_source" : {
          "person" : {
            "lastName" : "Miller"
          },
          "person.lastName" : "Smith"
        }

```

It becomes even weirder when I query these both return the document:

Object property:

```auto
    POST /storage-index/_search
    {
      "query": {
        "query_string": {
          "query": "person.lastName:Miller"
        }
      }
    }

```

Flat property:

```auto
    POST /storage-index/_search
    {
      "query": {
        "query_string": {
          "query": "person.lastName:Smith"
        }
      }
    }

```

What am I missing?

---

<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:** [March 8, 2022, 9:41am UTC](https://discuss.elastic.co/t/are-elasticsearch-object-properties-really-just-flat-properties-with-a-namespace/299054/2 "2022-03-08T09:41:45Z")

</div>

It's all flattened behind the scene. Which does not mean that you can see that in the source.

What does `GET /storage-index/_mapping` gives?

---

<div class="post-metadata">

**Author:** ![NashSLX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nashslx/32/47551_2.png) [@NashSLX](https://discuss.elastic.co/u/NashSLX)\
**Post date:** [March 8, 2022, 9:54am UTC](https://discuss.elastic.co/t/are-elasticsearch-object-properties-really-just-flat-properties-with-a-namespace/299054/3 "2022-03-08T09:54:17Z")

</div>

From my understanding you're essentially writing to the same field in two different ways. If you look at the mapping there's only one field for the lastName:

```auto
"mappings" : {
  "properties" : {
    "person" : {
      "properties" : {
        "lastName" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

```

The way the source is displayed is interesting, since from my understand this is essentially the same document (at least from a search point of view) as this would be:

```auto
"_source" : {
  "person" : {
    "lastName" : [
      "Miller",
      "Smith"
    ]
  }
}

```

I guess it's the only way to handle this without losing the differentiation completely.

---

<div class="post-metadata">

**Author:** ![Robert\_Krueger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robert_krueger/32/99210_2.png) [@Robert\_Krueger](https://discuss.elastic.co/u/Robert_Krueger)\
**Post date:** [March 8, 2022, 10:48am UTC](https://discuss.elastic.co/t/are-elasticsearch-object-properties-really-just-flat-properties-with-a-namespace/299054/4 "2022-03-08T10:48:19Z")

</div>

Ah, that's a good explanation 🙂 . Thanks!

Yeah the source display threw me off here as it definitely proves that there is some data stored in the system that lets it differentiate between the way this data came into the index. But that solves my problem.

I double-checked that the dynamically created mapping is as you suggested.

---

<div class="post-metadata">

**Author:** ![Robert\_Krueger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robert_krueger/32/99210_2.png) [@Robert\_Krueger](https://discuss.elastic.co/u/Robert_Krueger)\
**Post date:** [March 8, 2022, 2:25pm UTC](https://discuss.elastic.co/t/are-elasticsearch-object-properties-really-just-flat-properties-with-a-namespace/299054/5 "2022-03-08T14:25:10Z")

</div>

> [@Robert\_Krueger](#):
>
> `Smith`

There's still some weirdness here. If I update the field, behaviour is different depending on how I do it. Take a look:

```auto
POST storage-index/_update/k3qRaH8BanEsnFgaHdHH
{
  "doc": {
    "person.lastName": "Smithy"
  }
}

```

then

```auto
POST storage-index/_update/k3qRaH8BanEsnFgaHdHH
{
  "doc": {
    "person": {
      "lastName": "Miley"
    }
  }
}

```

Result in the index:

```auto
        "_source" : {
          "person" : {
            "lastName" : "Miley"
          },
          "person.lastName" : "Smithy"
        }

```

It really behaves as if it were a separate field, although the mapping in the index is shown as

```auto
        "person" : {
          "properties" : {
            "lastName" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              },
              "analyzer" : "default"
            }
          }
        },

```

and no other mapping for a field named lastName anywhere in the index.

---

<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:** [March 8, 2022, 3:37pm UTC](https://discuss.elastic.co/t/are-elasticsearch-object-properties-really-just-flat-properties-with-a-namespace/299054/6 "2022-03-08T15:37:37Z")

</div>

That's expected again.

There's is a difference between how the `_source` is processed and stored AND the way everything gets indexed.

---

<div class="post-metadata">

**Author:** ![Robert\_Krueger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robert_krueger/32/99210_2.png) [@Robert\_Krueger](https://discuss.elastic.co/u/Robert_Krueger)\
**Post date:** [March 10, 2022, 12:57pm UTC](https://discuss.elastic.co/t/are-elasticsearch-object-properties-really-just-flat-properties-with-a-namespace/299054/7 "2022-03-10T12:57:21Z")

</div>

But why should that influence how update behaves? If the two examples are just different syntax for the same thing I would expect the update to overwrite the entire field's value but it doesn't. Depending on what syntax I use for the update, one or the other is overwritten, which isn't consistent with this internally being an array. This is repeatable. I checked.

If I insert an array for lastName and then do the same update (with a single string value), the whole array is replaced with the single String.

---

<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:** [March 10, 2022, 2:20pm UTC](https://discuss.elastic.co/t/are-elasticsearch-object-properties-really-just-flat-properties-with-a-namespace/299054/8 "2022-03-10T14:20:13Z")

</div>

I see what you meant. I missed that point initially.

@jpountz do you think this should be viewed as a bug?

---

<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:** [April 7, 2022, 2:20pm UTC](https://discuss.elastic.co/t/are-elasticsearch-object-properties-really-just-flat-properties-with-a-namespace/299054/9 "2022-04-07T14:20:34Z")

</div>

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