private fun prepareMapping(index: String, defaultMappings: Map<String, Any>): Boolean { var success = true for (stringObjectEntry in defaultMappings.entrySet()) { val mapping = stringObjectEntry.getValue() as Map<String, Any> ?: throw RuntimeException("type mapping not defined") val putMappingRequestBuilder: PutMappingRequestBuilder = client.admin().indices().preparePutMapping().setIndices(index) putMappingRequestBuilder.setType(stringObjectEntry.getKey()) putMappingRequestBuilder.setSource(mapping) if (log.isLoggable(Level.FINE)) { log.fine("Elasticsearch create mapping for index '" + index + " and type '" + stringObjectEntry.getKey() + "': " + mapping) } val resp: PutMappingResponse = putMappingRequestBuilder.execute().actionGet() if (resp.isAcknowledged()) { if (log.isLoggable(Level.FINE)) { log.fine("Elasticsearch mapping for index '" + index + " and type '" + stringObjectEntry.getKey() + "' was acknowledged") } } else { success = false log.warning("Elasticsearch mapping creation was not acknowledged for index '" + index + " and type '" + stringObjectEntry.getKey() + "'") } } return success }
This method applies the supplied mapping to the index .