Skip to content

Rollover API failing with 400 in case settings name don't have "index." prefix or "index" section in json #53388

@shwetathareja

Description

@shwetathareja

Elasticsearch version (bin/elasticsearch --version): 7.6

Plugins installed: []

Description of the problem including expected versus actual behavior:
Rollover API takes index settings as input parameters. The settings can specified as one of the below options:

1.  "settings": {
      "index" : {
    	"number_of_shards": 2
      }
  }
 2.  "settings": {
    "index.number_of_shards": 2
  }
3. "settings": {
    "number_of_shards": 2
  }

But, with this PR. the #3 option doesn't work and throws error as

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "unknown setting [number_of_shards] did you mean [index.number_of_shards]?"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "unknown setting [number_of_shards] did you mean [index.number_of_shards]?"
  },
  "status" : 400
}

Fix:
There is normalize and settings validation logic in onlyCreateIndex method and after refactoring this code is not getting triggered during rollover flow which calls applyCreateIndexRequest method.

Settings.Builder updatedSettingsBuilder = Settings.builder();
        Settings build = updatedSettingsBuilder.put(request.settings()).normalizePrefix(IndexMetaData.INDEX_SETTING_PREFIX).build();
        indexScopedSettings.validate(build, true); // we do validate here - index setting must be consistent
        request.settings(build);

The normalize call should also run during rollover flow otherwise it breaks the expected behavior.

Steps to reproduce:

1. curl -XPUT localhost:9200/abc-000001
2. curl -XPUT localhost:9200/abc-000001/_alias/abc
3. curl -X POST "localhost:9200/abc/_rollover?pretty" -H 'Content-Type: application/json' -d'
{
"conditions": {
"max_age":   "1s"
},
"settings": {
"number_of_shards": 2
}
}
'

Tried running this in 7.5 with no issue and rollover works as expected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions