Field limits for objects vs flattened documents

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

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

response

    {
        "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

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

response

    {
	    "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.

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