Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/123761.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 123761
summary: Have create index return a bad request on poor formatting
area: Infra/Core
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,44 @@
- match: { error.type: "mapper_parsing_exception" }
- match: { error.reason: "Failed to parse mapping: The mapper type [invalid] declared on field [raw] does not exist. It might have been created within a future version or requires a plugin to be installed. Check the documentation." }
---
"Poorly formatted request returns bad_request":
- requires:
test_runner_features: [ capabilities ]
capabilities:
- method: PUT
path: /{index}
capabilities: [ poorly_formatted_bad_request ]
reason: "requires poorly_formatted_bad_request bug fix"

- do:
catch: bad_request
indices.create:
index: test_index
body:
mappings: "bad mappings"

- do:
catch: bad_request
indices.create:
index: test_index
body:
mappings:
properties: "bad properties"

- do:
catch: bad_request
indices.create:
index: test_index
body:
settings: "bad settings"

- do:
catch: bad_request
indices.create:
index: test_index
body:
aliases: "bad alias"
---
"Create index with hunspell missing dict":
- requires:
test_runner_features: [ capabilities ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,16 +410,17 @@ public CreateIndexRequest source(Map<String, ?> source, DeprecationHandler depre
for (Map.Entry<String, ?> entry : source.entrySet()) {
String name = entry.getKey();
if (SETTINGS.match(name, deprecationHandler)) {
if (entry.getValue() instanceof Map == false) {
throw new ElasticsearchParseException("key [settings] must be an object");
}
validateIsMap(SETTINGS.getPreferredName(), entry.getValue());
settings((Map<String, Object>) entry.getValue());
} else if (MAPPINGS.match(name, deprecationHandler)) {
validateIsMap(MAPPINGS.getPreferredName(), entry.getValue());
Map<String, Object> mappings = (Map<String, Object>) entry.getValue();
for (Map.Entry<String, Object> entry1 : mappings.entrySet()) {
validateIsMap(entry1.getKey(), entry1.getValue());
mapping(entry1.getKey(), (Map<String, Object>) entry1.getValue());
}
} else if (ALIASES.match(name, deprecationHandler)) {
validateIsMap(ALIASES.getPreferredName(), entry.getValue());
aliases((Map<String, Object>) entry.getValue());
} else {
throw new ElasticsearchParseException("unknown key [{}] for create index", name);
Expand All @@ -428,6 +429,12 @@ public CreateIndexRequest source(Map<String, ?> source, DeprecationHandler depre
return this;
}

static void validateIsMap(String key, Object value) {
if (value instanceof Map == false) {
throw new ElasticsearchParseException("key [{}] must be an object", key);
}
}

public String mappings() {
return this.mappings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ public class CreateIndexCapabilities {

private static final String NESTED_DENSE_VECTOR_SYNTHETIC_TEST = "nested_dense_vector_synthetic_test";

private static final String POORLY_FORMATTED_BAD_REQUEST = "poorly_formatted_bad_request";

private static final String HUNSPELL_DICT_400 = "hunspell_dict_400";

public static final Set<String> CAPABILITIES = Set.of(
LOGSDB_INDEX_MODE_CAPABILITY,
LOOKUP_INDEX_MODE_CAPABILITY,
NESTED_DENSE_VECTOR_SYNTHETIC_TEST,
POORLY_FORMATTED_BAD_REQUEST,
HUNSPELL_DICT_400
);
}