本文整理汇总了Java中org.elasticsearch.action.admin.indices.create.CreateIndexResponse.isAcknowledged方法的典型用法代码示例。如果您正苦于以下问题:Java CreateIndexResponse.isAcknowledged方法的具体用法?Java CreateIndexResponse.isAcknowledged怎么用?Java CreateIndexResponse.isAcknowledged使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.admin.indices.create.CreateIndexResponse
的用法示例。
在下文中一共展示了CreateIndexResponse.isAcknowledged方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
public void createIndex(String backendId, String type, String mapping, boolean async, int shards, int replicas) {
Settings settings = Settings.builder()//
.put("number_of_shards", shards)//
.put("number_of_replicas", replicas)//
.build();
CreateIndexResponse createIndexResponse = internalClient.admin().indices()//
.prepareCreate(toIndex0(backendId, type))//
.addMapping(type, mapping)//
.addAlias(new Alias(toAlias(backendId, type)))//
.setSettings(settings)//
.get();
if (!createIndexResponse.isAcknowledged())
throw Exceptions.runtime(//
"index [%s] creation not acknowledged by the whole cluster", //
toIndex0(backendId, type));
if (!async)
ensureGreen(backendId, type);
}
示例2: createIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
/**
* Create index.
*
* @return True if index create ok, false if index is already exist.
*/
public boolean createIndex() {
// check index exist:
IndicesAdminClient idc = client.admin().indices();
IndicesExistsResponse ier = idc.exists(new IndicesExistsRequest(index)).actionGet();
if (!ier.isExists()) {
log.info("Index not found. Auto-create...");
// create index:
CreateIndexResponse cir = idc.create(new CreateIndexRequest(index)).actionGet();
if (!cir.isAcknowledged()) {
throw new RuntimeException("Failed to create index.");
}
return true;
}
return false;
}
示例3: createIndexIfNotExists
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
public void createIndexIfNotExists(String index, String settingJson, Map<String, String> mappingJson) {
String formattedIndex = formatIndex(index);
IndicesAdminClient indicesClient = client.admin().indices();
IndicesExistsResponse existsResponse = indicesClient.prepareExists(formattedIndex).get();
if (existsResponse.isExists()) {
return;
}
CreateIndexRequestBuilder builder = indicesClient.prepareCreate(formattedIndex)
.setSettings(Settings.settingsBuilder().loadFromSource(settingJson));
mappingJson.forEach((k, v) -> {
builder.addMapping(k, v);
});
CreateIndexResponse indexResponse = builder.get();
if (!indexResponse.isAcknowledged()) {
throw new ElasticsearchException(String.format("index %s の作成に失敗しました", index));
}
}
示例4: checkForOrCreateIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
/**
* If ES already contains this instance's target index, then do nothing.
* Otherwise, create the index, then wait {@link #CREATE_SLEEP}.
* <p>
* The {@code client} field must point to a live, connected client.
* The {@code indexName} field must be non-null and point to the name
* of the index to check for existence or create.
*
* @param config the config for this ElasticSearchIndex
* @throws java.lang.IllegalArgumentException if the index could not be created
*/
private void checkForOrCreateIndex(Configuration config) {
Preconditions.checkState(null != client);
//Create index if it does not already exist
IndicesExistsResponse response = client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet();
if (!response.isExists()) {
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
ElasticSearchSetup.applySettingsFromTitanConf(settings, config, ES_CREATE_EXTRAS_NS);
CreateIndexResponse create = client.admin().indices().prepareCreate(indexName)
.setSettings(settings.build()).execute().actionGet();
try {
final long sleep = config.get(CREATE_SLEEP);
log.debug("Sleeping {} ms after {} index creation returned from actionGet()", sleep, indexName);
Thread.sleep(sleep);
} catch (InterruptedException e) {
throw new TitanException("Interrupted while waiting for index to settle in", e);
}
if (!create.isAcknowledged()) throw new IllegalArgumentException("Could not create index: " + indexName);
}
}
示例5: createMapping
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
protected boolean createMapping(MappingConfiguration mapping, String indexId) {
IndicesAdminClient indices = getClient().admin().indices();
Map<String, Object> schema = schemaGenerator.generate(mapping);
log.trace("Built schema creation request:\n{}", Arrays.toString(schema.entrySet().toArray()));
// create metadata mapping and schema mapping
CreateIndexRequestBuilder request = indices.prepareCreate(indexId)
.addMapping(MetadataDataMapping.METADATA_TYPE_NAME, getMetadataSchema())
.addMapping(mapping.getType(), schema);
if (mapping.hasIndexCreationRequest()) {
request.setSettings(mapping.getIndexCreationRequest());
}
CreateIndexResponse response = request.get();
log.debug("Created indices: {}, acknowledged: {}", response, response.isAcknowledged());
Map<String, Object> mdRecord = createMetadataRecord(mapping.getVersion(), mapping.getName());
IndexResponse mdResponse = getClient().prepareIndex(indexId, MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID).setSource(mdRecord).get();
log.debug("Saved mapping metadata '{}': {}", mdResponse.isCreated(), Arrays.toString(mdRecord.entrySet().toArray()));
return (mdResponse.isCreated() && response.isAcknowledged());
}
示例6: addSchema
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
private void addSchema(int iter) {
String indexIter = "";
if (iter > 0) {
indexIter += iter;
}
String mappingJSON = "{\"" + indexType + "\":{\"_timestamp\":{\"enabled\":true,\"store\":true,\"index\":\"not_analyzed\"},\"_all\":{\"enabled\":false},\"properties\":{\"trackId\":{\"type\":\"string\"},\"timestamp\":{\"type\":\"date\"},\"speed\":{\"type\":\"float\",\"index\":\"no\"}}}}";
CreateIndexRequestBuilder builder = client.admin().indices().prepareCreate(indexName + indexIter);
builder.addMapping(indexType, mappingJSON);
//builder.setSettings("index.number_of_shards", 1);
//builder.setSettings("index.number_of_replicas", 0);
//builder.setSettings("refresh_interval", "120s");
builder.setSettings("index.store.type", "memory");
CreateIndexResponse createResponse = builder.execute().actionGet();
if (!createResponse.isAcknowledged()) {
System.err.println("Index was not created!");
}
}
示例7: createIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
@Override
public void createIndex(String indexName, String indexType, Object source) {
logger.info(String.format("Generating index %s ...", indexName));
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
if (indexType != null) {
String settings = generateSettings(source);
if (settings != null) {
logger.info("Setting up...");
createIndexRequest.settings(settings);
}
}
logger.info("Mapping...");
String mapping = generateMapping(source);
createIndexRequest.mapping(indexType, mapping);
try {
CreateIndexResponse response = elasticSearchClient.admin().indices().create(createIndexRequest).actionGet();
if (response.isAcknowledged()) {
logger.info(String.format("Index %s created!", indexName));
}
} catch (ElasticsearchException ex) {
logger.error(String.format("Index %s was not created due some errors.", indexName), ex);
}
}
示例8: createMetaIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
private void createMetaIndex(final ElasticsearchConnection connection,
final String indexName,
int replicaCount) throws Exception {
try {
CreateIndexResponse response = new CreateIndexRequestBuilder(connection.getClient().admin().indices(), indexName)
.setSettings(
ImmutableSettings.builder()
.put("number_of_shards", 1)
.put("number_of_replicas", replicaCount)
)
.execute()
.get();
logger.info("'{}' creation acknowledged: {}", indexName, response.isAcknowledged());
if (!response.isAcknowledged()) {
logger.error("Index {} could not be created.", indexName);
}
} catch (Exception e) {
if (null != e.getCause()) {
logger.error("Index {} could not be created: {}", indexName, e.getCause().getLocalizedMessage());
} else {
logger.error("Index {} could not be created: {}", indexName, e.getLocalizedMessage());
}
}
}
示例9: testCreateCompanyIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
@Test
public void testCreateCompanyIndex() throws ElasticsearchException, IOException {
CreateIndexResponse response =
client
.admin()
.indices()
.prepareCreate(indexName)
.setSettings(
XContentFactory.jsonBuilder().field("number_of_shards", 1)
.field("number_of_replicas", 0)).execute().actionGet();
if (response.isAcknowledged()) {
System.out.println("Index creation succeeded.");
} else {
System.err.println("Index creation failed.");
}
}
示例10: testCreateIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
@Test
public void testCreateIndex() throws IOException {
CreateIndexRequestBuilder cirb = client.admin().indices().prepareCreate(indexName).setSource(XContentFactory.jsonBuilder()
.startObject()
.startObject("settings")
.field("number_of_shards", 1)
.field("number_of_replicas", 0)
.endObject()
.endObject());
CreateIndexResponse response = cirb.execute().actionGet();
if(response.isAcknowledged()) {
System.out.println("Index created.");
} else {
System.err.println("Index creation failed.");
}
}
开发者ID:destiny1020,项目名称:elasticsearch-java-client-examples,代码行数:18,代码来源:NestedObjectMappingExamples.java
示例11: setup
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
public void setup() throws IOException, NoSuchFieldException, IllegalAccessException {
String key;
CreateIndexResponse ciResp;
Reflections reflections = new Reflections("org.apache.usergrid.chop.webapp.dao");
Set<Class<? extends Dao>> daoClasses = reflections.getSubTypesOf(Dao.class);
IndicesAdminClient client = elasticSearchClient.getClient().admin().indices();
for (Class<? extends Dao> daoClass : daoClasses) {
key = daoClass.getDeclaredField("DAO_INDEX_KEY").get(null).toString();
if (!client.exists(new IndicesExistsRequest(key)).actionGet().isExists()) {
ciResp = client.create(new CreateIndexRequest(key)).actionGet();
if (ciResp.isAcknowledged()) {
LOG.debug("Index for key {} didn't exist, now created", key);
} else {
LOG.debug("Could not create index for key: {}", key);
}
} else {
LOG.debug("Key {} already exists", key);
}
}
}
示例12: initIndexes
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
public void initIndexes(String indexName, Class<?>[] classes) throws Exception {
// check if existing before
final ActionFuture<IndicesExistsResponse> indexExistFuture = esClient.getClient().admin().indices().exists(new IndicesExistsRequest(indexName));
IndicesExistsResponse response;
response = indexExistFuture.get();
if (!response.isExists()) {
// create the index and add the mapping
CreateIndexRequestBuilder createIndexRequestBuilder = esClient.getClient().admin().indices().prepareCreate(indexName);
for (Class<?> clazz : classes) {
System.out.println(mappingBuilder.getMapping(clazz));
createIndexRequestBuilder.addMapping(clazz.getSimpleName().toLowerCase(), mappingBuilder.getMapping(clazz));
}
final CreateIndexResponse createResponse = createIndexRequestBuilder.execute().actionGet();
if (!createResponse.isAcknowledged()) {
throw new Exception("Failed to create index <" + indexName + ">");
}
}
}
开发者ID:alien4cloud,项目名称:elasticsearch-mapping-parent,代码行数:21,代码来源:ElasticSearchInsertMappingTest.java
示例13: createIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
private void createIndex() {
Settings settings = Settings.builder()
.put("index.refresh_interval", "-1")
.put("index.translog.sync_interval", "10s")
.put("index.translog.durability", "async")
.put("index.number_of_replicas", "0")
.build();
CreateIndexResponse res = esClient.prepareCreate().setSettings(settings).get();
if (!res.isAcknowledged()) {
throw new IndexingException("Fail to create index for " + this.kbId);
}
}
示例14: crateIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
public boolean crateIndex(LogcenterConfig config) {
String indexName = buildIndexName(config);
CreateIndexResponse response = ElasticsearchClient.getClient().admin().indices().prepareCreate(indexName)
.setSettings(Settings.builder()
.put("index.number_of_shards", 5)
.put("index.number_of_replicas", 1)
)
.addMapping(config.getTypeName(), config.getTypeMapping())
.get();
return response.isAcknowledged();
}
示例15: createIndex
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; //导入方法依赖的package包/类
/**
* 创建索引
*
* @param indexName
*
* @return
*/
public boolean createIndex(String indexName) {
TransportClient client = esClientFactory.getClient();
CreateIndexResponse response = null;
// 如果存在返回true
if (client.admin().indices().prepareExists(esClientFactory.getIndexs(indexName)).get().isExists()) {
return true;
} else {
response = client.admin().indices().prepareCreate(esClientFactory.getIndexs(indexName)).execute().actionGet();
}
return response.isAcknowledged();
}