use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project play2-elasticsearch by cleverage.
the class IndexService method createMapping.
/**
* Create Mapping ( for example mapping type : nested, geo_point )
* see http://www.elasticsearch.org/guide/reference/mapping/
* <p/>
* {
* "tweet" : {
* "properties" : {
* "message" : {"type" : "string", "store" : "yes"}
* }
* }
* }
*
* @param indexName
* @param indexType
* @param indexMapping
*/
public static PutMappingResponse createMapping(String indexName, String indexType, String indexMapping) {
Logger.debug("ElasticSearch : creating mapping [" + indexName + "/" + indexType + "] : " + indexMapping);
PutMappingResponse response = IndexClient.client.admin().indices().preparePutMapping(indexName).setType(indexType).setSource(indexMapping).execute().actionGet();
return response;
}
use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project fess by codelibs.
the class FessEsClient method addMapping.
public void addMapping(final String index, final String docType, final String indexName) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final GetMappingsResponse getMappingsResponse = client.admin().indices().prepareGetMappings(indexName).execute().actionGet(fessConfig.getIndexIndicesTimeout());
final ImmutableOpenMap<String, MappingMetaData> indexMappings = getMappingsResponse.mappings().get(indexName);
if (indexMappings == null || !indexMappings.containsKey(docType)) {
String source = null;
final String mappingFile = indexConfigPath + "/" + index + "/" + docType + ".json";
try {
source = FileUtil.readUTF8(mappingFile);
} catch (final Exception e) {
logger.warn(mappingFile + " is not found.", e);
}
try {
final PutMappingResponse putMappingResponse = client.admin().indices().preparePutMapping(indexName).setType(docType).setSource(source, XContentFactory.xContentType(source)).execute().actionGet(fessConfig.getIndexIndicesTimeout());
if (putMappingResponse.isAcknowledged()) {
logger.info("Created " + indexName + "/" + docType + " mapping.");
} else {
logger.warn("Failed to create " + indexName + "/" + docType + " mapping.");
}
final String dataPath = indexConfigPath + "/" + index + "/" + docType + ".bulk";
if (ResourceUtil.isExist(dataPath)) {
insertBulkData(fessConfig, index, docType, dataPath);
}
} catch (final Exception e) {
logger.warn("Failed to create " + indexName + "/" + docType + " mapping.", e);
}
} else if (logger.isDebugEnabled()) {
logger.debug(indexName + "/" + docType + " mapping exists.");
}
}
Aggregations