本文整理汇总了Java中org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse.isAcknowledged方法的典型用法代码示例。如果您正苦于以下问题:Java PutMappingResponse.isAcknowledged方法的具体用法?Java PutMappingResponse.isAcknowledged怎么用?Java PutMappingResponse.isAcknowledged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse
的用法示例。
在下文中一共展示了PutMappingResponse.isAcknowledged方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateMappingOnMaster
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
public void updateMappingOnMaster(String index, String type, Mapping mappingUpdate, final TimeValue timeout, final MappingUpdateListener listener) {
final PutMappingRequestBuilder request = updateMappingRequest(index, type, mappingUpdate, timeout);
if (listener == null) {
request.execute();
} else {
final ActionListener<PutMappingResponse> actionListener = new ActionListener<PutMappingResponse>() {
@Override
public void onResponse(PutMappingResponse response) {
if (response.isAcknowledged()) {
listener.onMappingUpdate();
} else {
listener.onFailure(new TimeoutException("Failed to acknowledge the mapping response within [" + timeout + "]"));
}
}
@Override
public void onFailure(Throwable e) {
listener.onFailure(e);
}
};
request.execute(actionListener);
}
}
示例2: addOrUpdateMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
/**
* This method will update type and mapping under already created index.
*
* @param indexName String
* @param typeName String
* @param mapping String
* @return boolean
*/
@SuppressWarnings("deprecation")
public static boolean addOrUpdateMapping(String indexName, String typeName, String mapping) {
try {
PutMappingResponse response = ConnectionManager.getClient().admin().indices()
.preparePutMapping(indexName)
.setType(typeName).setSource(mapping).get();
if (response.isAcknowledged()) {
return true;
}
} catch (Exception e) {
ProjectLogger.log(e.getMessage(), e);
}
return false;
}
示例3: createMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
public boolean createMapping(Class<?> docType) {
Mapping mapping = getMappingFromClass(docType);
IndicesAdminClient idc = client.admin().indices();
GetMappingsResponse gmr = idc.getMappings(new GetMappingsRequest()).actionGet();
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = gmr.getMappings();
if (mappings.containsKey(mapping.getType())) {
log.info("Found mapping for class " + docType.getName() + ".");
return false;
}
log.info("Mapping not found for class " + docType.getName() + ". Auto-create...");
PutMappingResponse pmr = idc.preparePutMapping(index).setType(mapping.getType()).setSource(mapping.getSource())
.get();
if (!pmr.isAcknowledged()) {
throw new RuntimeException("Failed to create mapping for class:" + docType.getName() + ".");
}
return true;
}
示例4: createMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
public boolean createMapping(Class<?> mappingClass) {
this.startElasticSearchClient();
if (!EsIndexDataStructure.indexExist(this.clientElasticSearch, mappingClass)) {
ESIndex annotation = mappingClass.getAnnotation(ESIndex.class);
String message = "Index %s does not exist. You must create it before you create a type.";
message = message.replaceFirst("%s", (annotation == null ? "" : annotation.name()));
throw new RuntimeException(message);
}
PutMappingResponse response = EsIndexDataStructure.createMapping(this.clientElasticSearch, mappingClass);
if (this.configurationElasticSearch.isAutomaticClientClose()) {
this.shutdownElasticSearchClient();
}
return (response != null) ? response.isAcknowledged() : false;
}
示例5: updateMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
protected boolean updateMapping(String indexId, MappingConfiguration mapping) throws SinkError {
double version = getCurrentVersion(indexId);
log.info("Existing mapping version is {}, vs. c version {}", version, mapping.getVersion());
if (version < 0) {
throw new SinkError("Database inconsistency. Metadata version not found in type %s", MetadataDataMapping.METADATA_TYPE_NAME);
}
if (version != mapping.getVersion()) {
throw new SinkError("Database schema version inconsistency. Version numbers don't match. Database version number %d != mapping version number %d",
version, mapping.getVersion());
}
// schema can be updated
Map<String, Object> schema = schemaGenerator.generate(mapping);
PutMappingRequestBuilder request = getClient().admin().indices()
.preparePutMapping(indexId)
.setType(mapping.getType())
.setSource(schema);
PutMappingResponse updateMappingResponse = request.get();
log.info("Update mapping of type {} acknowledged: {}", mapping.getType(), updateMappingResponse.isAcknowledged());
if (!updateMappingResponse.isAcknowledged()) {
log.error("Problem updating mapping for type {}", mapping.getType());
}
Map<String, Object> updatedMetadata = createUpdatedMetadata(indexId);
UpdateResponse mdUpdate = getClient().prepareUpdate(indexId, MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID)
.setDoc(updatedMetadata).get();
log.info("Update metadata record created: {} | id = {} @ {}/{}",
mdUpdate.isCreated(), mdUpdate.getId(), mdUpdate.getIndex(), mdUpdate.getType());
return (mdUpdate.getId().equals(MetadataDataMapping.METADATA_ROW_ID)
&& updateMappingResponse.isAcknowledged());
}
示例6: prepareMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
/**
* This method applies the supplied mapping to the index.
*
* @param index The name of the index
* @param defaultMappings The default mappings
* @return true if the mapping was successful
*/
@SuppressWarnings("unchecked")
private boolean prepareMapping(String index, Map<String, Object> defaultMappings) {
boolean success = true;
for (Map.Entry<String, Object> stringObjectEntry : defaultMappings.entrySet()) {
Map<String, Object> mapping = (Map<String, Object>) stringObjectEntry.getValue();
if (mapping == null) {
throw new RuntimeException("type mapping not defined");
}
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);
}
PutMappingResponse resp = 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;
}
示例7: putMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
public void putMapping(String backendId, String type, String mapping) {
PutMappingResponse putMappingResponse = internalClient.admin().indices()//
.preparePutMapping(toAlias(backendId, type))//
.setType(type)//
.setSource(mapping)//
.setUpdateAllTypes(true)//
.get();
if (!putMappingResponse.isAcknowledged())
throw Exceptions.runtime(//
"mapping [%s] update not acknowledged by the whole cluster", //
type);
}
示例8: open
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
public void open() {
final IndicesExistsResponse existsResponse = client.admin().indices()
.prepareExists(index).execute().actionGet();
if (!existsResponse.isExists()) {
final CreateIndexResponse createIndexResponse = client.admin()
.indices().prepareCreate(index).execute().actionGet();
if (!createIndexResponse.isAcknowledged()) {
throw new TasteException("Failed to create " + index
+ " index.");
}
}
if (mappingBuilder != null) {
final GetMappingsResponse response = client.admin().indices()
.prepareGetMappings(index).setTypes(type).execute()
.actionGet();
if (response.mappings().isEmpty()) {
final PutMappingResponse putMappingResponse = client.admin()
.indices().preparePutMapping(index).setType(type)
.setSource(mappingBuilder).execute().actionGet();
if (!putMappingResponse.isAcknowledged()) {
throw new TasteException("Failed to create a mapping of"
+ index + "/" + type);
}
}
}
}
示例9: createMapping
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
public PutMappingResponse createMapping(final String index,
final BuilderCallback<PutMappingRequestBuilder> builder) {
final PutMappingResponse actionGet = builder
.apply(client().admin().indices().preparePutMapping(index))
.execute().actionGet();
if (!actionGet.isAcknowledged()) {
onFailure("Failed to create a mapping for " + index + ".",
actionGet);
}
return actionGet;
}
示例10: createMappings
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
/**
* Setup ElasticSearch type mappings as a template that applies to all new indexes.
* Applies to all indexes that* start with our prefix.
*/
private void createMappings(final String indexName) {
//Added For Graphite Metrics
PutMappingResponse pitr = provider.getClient().admin().indices().preparePutMapping( indexName ).setType( "entity" ).setSource(
getMappingsContent() ).execute().actionGet();
if ( !pitr.isAcknowledged() ) {
throw new RuntimeException( "Unable to create default mappings" );
}
}
示例11: createMappings
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
/**
* Setup ElasticSearch type mappings as a template that applies to all new indexes.
* Applies to all indexes that* start with our prefix.
*/
private void createMappings(final String indexName) throws IOException {
//Added For Graphite Metrics
Timer.Context timePutIndex = mappingTimer.time();
PutMappingResponse pitr = esProvider.getClient().admin().indices().preparePutMapping( indexName ).setType( "entity" ).setSource(
getMappingsContent() ).execute().actionGet();
timePutIndex.stop();
if ( !pitr.isAcknowledged() ) {
throw new IndexException( "Unable to create default mappings" );
}
}
示例12: doItemMappingCreation
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
private void doItemMappingCreation(final Params params,
final RequestHandler.OnErrorListener listener,
final Map<String, Object> requestMap,
final Map<String, Object> paramMap, final RequestHandlerChain chain) {
final String index = params.param(
TasteConstants.REQUEST_PARAM_ITEM_INDEX, params.param("index"));
final String type = params.param(
TasteConstants.REQUEST_PARAM_ITEM_TYPE,
TasteConstants.ITEM_TYPE);
final String itemIdField = params.param(
TasteConstants.REQUEST_PARAM_ITEM_ID_FIELD,
TasteConstants.ITEM_ID_FIELD);
final String timestampField = params.param(
TasteConstants.REQUEST_PARAM_TIMESTAMP_FIELD,
TasteConstants.TIMESTAMP_FIELD);
try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
final ClusterHealthResponse healthResponse = client
.admin()
.cluster()
.prepareHealth(index)
.setWaitForYellowStatus()
.setTimeout(
params.param("timeout",
DEFAULT_HEALTH_REQUEST_TIMEOUT)).execute()
.actionGet();
if (healthResponse.isTimedOut()) {
listener.onError(new OperationFailedException(
"Failed to create index: " + index + "/" + type));
}
final XContentBuilder builder = jsonBuilder//
.startObject()//
.startObject(type)//
.startObject("properties")//
// @timestamp
.startObject(timestampField)//
.field("type", "date")//
.field("format", "date_optional_time")//
.endObject()//
// item_id
.startObject(itemIdField)//
.field("type", "long")//
.endObject()//
// system_id
.startObject("system_id")//
.field("type", "string")//
.field("index", "not_analyzed")//
.endObject()//
.endObject()//
.endObject()//
.endObject();
final PutMappingResponse mappingResponse = client.admin().indices()
.preparePutMapping(index).setType(type).setSource(builder)
.execute().actionGet();
if (mappingResponse.isAcknowledged()) {
fork(() -> execute(params, listener, requestMap, paramMap,
chain));
} else {
listener.onError(new OperationFailedException(
"Failed to create mapping for " + index + "/" + type));
}
} catch (final Exception e) {
listener.onError(e);
}
}
示例13: doPreferenceMappingCreation
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
private void doPreferenceMappingCreation(final Params params,
final RequestHandler.OnErrorListener listener,
final Map<String, Object> requestMap,
final Map<String, Object> paramMap, final RequestHandlerChain chain) {
final String index = params.param("index");
final String type = params
.param("type", TasteConstants.PREFERENCE_TYPE);
final String userIdField = params.param(
TasteConstants.REQUEST_PARAM_USER_ID_FIELD,
TasteConstants.USER_ID_FIELD);
final String itemIdField = params.param(
TasteConstants.REQUEST_PARAM_ITEM_ID_FIELD,
TasteConstants.ITEM_ID_FIELD);
final String valueField = params.param(
TasteConstants.REQUEST_PARAM_VALUE_FIELD,
TasteConstants.VALUE_FIELD);
final String timestampField = params.param(
TasteConstants.REQUEST_PARAM_TIMESTAMP_FIELD,
TasteConstants.TIMESTAMP_FIELD);
try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
final ClusterHealthResponse healthResponse = client
.admin()
.cluster()
.prepareHealth(index)
.setWaitForYellowStatus()
.setTimeout(
params.param("timeout",
DEFAULT_HEALTH_REQUEST_TIMEOUT)).execute()
.actionGet();
if (healthResponse.isTimedOut()) {
listener.onError(new OperationFailedException(
"Failed to create index: " + index + "/" + type));
}
final XContentBuilder builder = jsonBuilder//
.startObject()//
.startObject(type)//
.startObject("properties")//
// @timestamp
.startObject(timestampField)//
.field("type", "date")//
.field("format", "date_optional_time")//
.endObject()//
// user_id
.startObject(userIdField)//
.field("type", "long")//
.endObject()//
// item_id
.startObject(itemIdField)//
.field("type", "long")//
.endObject()//
// value
.startObject(valueField)//
.field("type", "double")//
.endObject()//
.endObject()//
.endObject()//
.endObject();
final PutMappingResponse mappingResponse = client.admin().indices()
.preparePutMapping(index).setType(type).setSource(builder)
.execute().actionGet();
if (mappingResponse.isAcknowledged()) {
fork(() -> execute(params, listener, requestMap, paramMap,
chain));
} else {
listener.onError(new OperationFailedException(
"Failed to create mapping for " + index + "/" + type));
}
} catch (final Exception e) {
listener.onError(e);
}
}
示例14: doUserMappingCreation
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
private void doUserMappingCreation(final Params params,
final RequestHandler.OnErrorListener listener,
final Map<String, Object> requestMap,
final Map<String, Object> paramMap, final RequestHandlerChain chain) {
final String index = params.param(
TasteConstants.REQUEST_PARAM_USER_INDEX, params.param("index"));
final String type = params.param(
TasteConstants.REQUEST_PARAM_USER_TYPE,
TasteConstants.USER_TYPE);
final String userIdField = params.param(
TasteConstants.REQUEST_PARAM_USER_ID_FIELD,
TasteConstants.USER_ID_FIELD);
final String timestampField = params.param(
TasteConstants.REQUEST_PARAM_TIMESTAMP_FIELD,
TasteConstants.TIMESTAMP_FIELD);
try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
final ClusterHealthResponse healthResponse = client
.admin()
.cluster()
.prepareHealth(index)
.setWaitForYellowStatus()
.setTimeout(
params.param("timeout",
DEFAULT_HEALTH_REQUEST_TIMEOUT)).execute()
.actionGet();
if (healthResponse.isTimedOut()) {
listener.onError(new OperationFailedException(
"Failed to create index: " + index + "/" + type));
}
final XContentBuilder builder = jsonBuilder//
.startObject()//
.startObject(type)//
.startObject("properties")//
// @timestamp
.startObject(timestampField)//
.field("type", "date")//
.field("format", "date_optional_time")//
.endObject()//
// user_id
.startObject(userIdField)//
.field("type", "long")//
.endObject()//
// system_id
.startObject("system_id")//
.field("type", "string")//
.field("index", "not_analyzed")//
.endObject()//
.endObject()//
.endObject()//
.endObject();
final PutMappingResponse mappingResponse = client.admin().indices()
.preparePutMapping(index).setType(type).setSource(builder)
.execute().actionGet();
if (mappingResponse.isAcknowledged()) {
fork(() -> execute(params, listener, requestMap, paramMap,
chain));
} else {
listener.onError(new OperationFailedException(
"Failed to create mapping for " + index + "/" + type));
}
} catch (final Exception e) {
listener.onError(e);
}
}
示例15: testCreateMappings
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; //导入方法依赖的package包/类
@Test
public void testCreateMappings() throws IOException {
// mapping for the blogpost
XContentBuilder builder =
XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
// field user
.startObject("user")
.startObject("properties")
.startObject("name")
.field("type", "string")
.startObject("fields")
.startObject("raw")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
// field title
.startObject("title")
.field("type", "string")
.endObject()
// field body
.startObject("body")
.field("type", "string")
.endObject()
.endObject()
.endObject();
PutMappingResponse response = client.admin().indices().preparePutMapping(indexName).setType(typeBlogpost)
.setSource(builder).execute().actionGet();
if (response.isAcknowledged()) {
System.out.println("blogpost mapping created !");
} else {
System.err.println("blogpost mapping creation failed !");
}
// mapping for user
builder =
XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
// field name
.startObject("name")
.field("type", "string")
.endObject()
// field email
.startObject("email")
.field("type", "string")
.endObject()
// field dob
.startObject("dob")
.field("type", "date")
.endObject()
.endObject()
.endObject();
response = client.admin().indices().preparePutMapping(indexName).setType(typeUser)
.setSource(builder).execute().actionGet();
if (response.isAcknowledged()) {
System.out.println("user mapping created !");
} else {
System.err.println("user mapping creation failed !");
}
}