Skip to content

Commit f409d60

Browse files
committed
refactor
1 parent a9d4324 commit f409d60

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,8 @@ private CreateIndexRequest mapping(BytesReference source, XContentType xContentT
286286
}
287287

288288
private CreateIndexRequest mapping(String type, Map<String, ?> source) {
289-
if (source.isEmpty()) {
290-
// If no source is provided we return empty mappings
291-
return mapping(EMPTY_MAPPINGS);
292-
} else if (source.size() == 1 && source.containsKey("properties") && ((Map) source.get("properties")).isEmpty()) {
293-
// TODO-MP change if clause
294-
// return empty mapping if source is only "empty" properties
289+
if (isSourceEffectivelyEmpty(source)) {
290+
// If no source is provided of it's effectively empty we return empty mappings
295291
return mapping(EMPTY_MAPPINGS);
296292
} else if (source.size() != 1 || source.containsKey(type) == false) {
297293
// wrap it in a type map if its not
@@ -309,6 +305,22 @@ private CreateIndexRequest mapping(String type, Map<String, ?> source) {
309305
}
310306
}
311307

308+
/**
309+
* Checks if the source map is effectively empty.
310+
*
311+
* @param source the source map to check
312+
* @return true if the source map is empty or contains only an empty "properties" key, false otherwise
313+
*/
314+
private boolean isSourceEffectivelyEmpty(Map<String, ?> source) {
315+
if (source.isEmpty()) {
316+
return true;
317+
}
318+
if (source.size() == 1 && source.containsKey("properties")) {
319+
return ((Map<?, ?>) source.get("properties")).isEmpty();
320+
}
321+
return false;
322+
}
323+
312324
/**
313325
* The cause for this index creation.
314326
*/

0 commit comments

Comments
 (0)