REST Create Index: Not taking JSON index settings into account unless wrapped in settings.

This commit is contained in:
kimchy 2010-12-29 12:10:51 +02:00
parent d8aef57baa
commit c8bfa455ad
1 changed files with 7 additions and 0 deletions

View File

@ -61,15 +61,22 @@ public class RestCreateIndexAction extends BaseRestHandler {
try { try {
Map<String, Object> source = XContentFactory.xContent(xContentType) Map<String, Object> source = XContentFactory.xContent(xContentType)
.createParser(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength()).mapAndClose(); .createParser(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength()).mapAndClose();
boolean found = false;
if (source.containsKey("settings")) { if (source.containsKey("settings")) {
createIndexRequest.settings((Map<String, Object>) source.get("settings")); createIndexRequest.settings((Map<String, Object>) source.get("settings"));
found = true;
} }
if (source.containsKey("mappings")) { if (source.containsKey("mappings")) {
found = true;
Map<String, Object> mappings = (Map<String, Object>) source.get("mappings"); Map<String, Object> mappings = (Map<String, Object>) source.get("mappings");
for (Map.Entry<String, Object> entry : mappings.entrySet()) { for (Map.Entry<String, Object> entry : mappings.entrySet()) {
createIndexRequest.mapping(entry.getKey(), (Map<String, Object>) entry.getValue()); createIndexRequest.mapping(entry.getKey(), (Map<String, Object>) entry.getValue());
} }
} }
if (!found) {
// the top level are settings, use them
createIndexRequest.settings(source);
}
} catch (Exception e) { } catch (Exception e) {
try { try {
channel.sendResponse(new XContentThrowableRestResponse(request, e)); channel.sendResponse(new XContentThrowableRestResponse(request, e));