@Override
@SuppressWarnings("unchecked")
public boolean putMapping(String indexName, String type, Object mapping) {
Assert.notNull(indexName, "No index defined for putMapping()");
Assert.notNull(type, "No type defined for putMapping()");
try {
Object source = null;
if (mapping instanceof String) {
source = String.valueOf(mapping);
} else if (mapping instanceof Map) {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map((Map) mapping);
source = builder.string();
} else if (mapping instanceof XContentBuilder) {
source = ((XContentBuilder) mapping).string();
} else if (mapping instanceof DocumentMapper) {
source = ((DocumentMapper) mapping).mappingSource().toString();
}
PutMapping.Builder requestBuilder = new PutMapping.Builder(indexName, type, source);
return executeWithAcknowledge(requestBuilder.build());
} catch (Exception e) {
throw new ElasticsearchException("Failed to build mapping for " + indexName + ":" + type, e);
}
}