# Field limits for objects vs flattened documents

**URL:** <https://discuss.elastic.co/t/field-limits-for-objects-vs-flattened-documents/265663>\
**Category:** Elasticsearch\
**Created:** [February 26, 2021, 8:19pm UTC](https://discuss.elastic.co/t/field-limits-for-objects-vs-flattened-documents/265663 "2021-02-26T20:19:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![acmatt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/acmatt/32/84628_2.png) [@acmatt](https://discuss.elastic.co/u/acmatt)\
**Post date:** [February 26, 2021, 8:19pm UTC](https://discuss.elastic.co/t/field-limits-for-objects-vs-flattened-documents/265663/1 "2021-02-26T20:19:05Z")

</div>

I recently ran into an issue when creating indexes and wanted to confirm if my understanding was correct.

When I attempt to create a new index, with a `total_fields.limit` of `1`, and a single object with a single field I receive an `illegal_argument_exception`

**request**

```auto
    PUT /test-index-1
    {
    	"settings": {
    		"index.mapping.total_fields.limit": 1
    	},
    	"mappings": {
    		"properties": {
    			"foo": {
                    "properties": {
                        "bar": {
                              "type": "keyword"
                        }
                    }
                }
            }
        }
    }

```

**response**

```auto
    {
        "error": {
            "root_cause": [
                {
                    "type": "illegal_argument_exception",
                    "reason": "Limit of total fields [1] in index [test-index-1] has been exceeded"
                }
            ],
            "type": "illegal_argument_exception",
            "reason": "Limit of total fields [1] in index [test-index-1] has been exceeded"
        },
        "status": 400
    }

```

However, if I flatten the object I do not receive the same error  
**request**

```auto
    PUT /test-index-2
    {
    	"settings": {
    		"index.mapping.total_fields.limit": 1
    	},
    	"mappings": {
    		"properties": {
    			"foo_bar": {"type": "keyword"}
            }
        }
    }

```

**response**

```auto
    {
	    "acknowledged": true,
	    "shards_acknowledged": true,
	    "index": "test-index-2"
    }

```

Based on these examples I have a couple of question:

1. Does creating an object with a single property really create more than a single field? My understanding is that Elasticsearch will flatten these objects so they two examples should be equivalent.  
I increased `index.mapping.total_fields.limit` to 2, and inserted a few identical documents into both `test-index-1` and `test-index-2`. The sizes of both Elasticsearch indexes are the same, and the Lucene data in the Elasticsearch `data` directory on disk looks the same.

2. Is this just a bug in the way the index PUT endpoint counts fields?

Thanks in advance for any replies. Interested in learning more about how this works.

---

<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:** [March 26, 2021, 8:19pm UTC](https://discuss.elastic.co/t/field-limits-for-objects-vs-flattened-documents/265663/2 "2021-03-26T20:19:40Z")

</div>

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