use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project uavstack by uavorg.
the class ESClient method creatIndex.
/**
* creatIndex
*
* @param index
* @return
*/
public boolean creatIndex(String index) {
CreateIndexRequest cir = new CreateIndexRequest(index);
CreateIndexResponse resp = client.admin().indices().create(cir).actionGet();
if (resp.isAcknowledged()) {
return true;
}
return false;
}
use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project syncope by apache.
the class ElasticsearchReindex method doExecute.
@Override
protected String doExecute(final boolean dryRun) throws JobExecutionException {
if (!dryRun) {
try {
LOG.debug("Start rebuild index {}", AuthContextUtils.getDomain().toLowerCase());
IndicesExistsResponse existsIndexResponse = client.admin().indices().exists(new IndicesExistsRequest(AuthContextUtils.getDomain().toLowerCase())).get();
if (existsIndexResponse.isExists()) {
DeleteIndexResponse deleteIndexResponse = client.admin().indices().delete(new DeleteIndexRequest(AuthContextUtils.getDomain().toLowerCase())).get();
LOG.debug("Successfully removed {}: {}", AuthContextUtils.getDomain().toLowerCase(), deleteIndexResponse);
}
XContentBuilder settings = XContentFactory.jsonBuilder().startObject().startObject("analysis").startObject("analyzer").startObject("string_lowercase").field("type", "custom").field("tokenizer", "standard").field("filter").startArray().value("lowercase").endArray().endObject().endObject().endObject().endObject();
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startArray("dynamic_templates").startObject().startObject("strings").field("match_mapping_type", "string").startObject("mapping").field("type", "keyword").field("analyzer", "string_lowercase").endObject().endObject().endObject().endArray().endObject();
CreateIndexResponse createIndexResponse = client.admin().indices().create(new CreateIndexRequest(AuthContextUtils.getDomain().toLowerCase()).settings(settings).mapping(AnyTypeKind.USER.name(), mapping).mapping(AnyTypeKind.GROUP.name(), mapping).mapping(AnyTypeKind.ANY_OBJECT.name(), mapping)).get();
LOG.debug("Successfully created {}: {}", AuthContextUtils.getDomain().toLowerCase(), createIndexResponse);
LOG.debug("Indexing users...");
for (int page = 1; page <= (userDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
for (User user : userDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
IndexResponse response = client.prepareIndex(AuthContextUtils.getDomain().toLowerCase(), AnyTypeKind.USER.name(), user.getKey()).setSource(elasticsearchUtils.builder(user)).get();
LOG.debug("Index successfully created for {}: {}", user, response);
}
}
LOG.debug("Indexing groups...");
for (int page = 1; page <= (groupDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
for (Group group : groupDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
IndexResponse response = client.prepareIndex(AuthContextUtils.getDomain().toLowerCase(), AnyTypeKind.GROUP.name(), group.getKey()).setSource(elasticsearchUtils.builder(group)).get();
LOG.debug("Index successfully created for {}: {}", group, response);
}
}
LOG.debug("Indexing any objects...");
for (int page = 1; page <= (anyObjectDAO.count() / AnyDAO.DEFAULT_PAGE_SIZE) + 1; page++) {
for (AnyObject anyObject : anyObjectDAO.findAll(page, AnyDAO.DEFAULT_PAGE_SIZE)) {
IndexResponse response = client.prepareIndex(AuthContextUtils.getDomain().toLowerCase(), AnyTypeKind.ANY_OBJECT.name(), anyObject.getKey()).setSource(elasticsearchUtils.builder(anyObject)).get();
LOG.debug("Index successfully created for {}: {}", anyObject, response);
}
}
LOG.debug("Rebuild index {} successfully completed", AuthContextUtils.getDomain().toLowerCase());
} catch (Exception e) {
throw new JobExecutionException("While rebuilding index " + AuthContextUtils.getDomain().toLowerCase(), e);
}
}
return "SUCCESS";
}
use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project incubator-skywalking by apache.
the class ElasticSearchClient method createIndex.
public boolean createIndex(String indexName, String indexType, Settings settings, XContentBuilder mappingBuilder) {
if (!ready) {
throw new ElasticSearchClientNotReadyException();
}
IndicesAdminClient adminClient = client.admin().indices();
indexName = formatIndexName(indexName);
CreateIndexResponse response = adminClient.prepareCreate(indexName).setSettings(settings).addMapping(indexType, mappingBuilder).get();
logger.info("create {} index with type of {} finished, isAcknowledged: {}", indexName, indexType, response.isAcknowledged());
return response.isShardsAcked();
}
use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project blog-example by my-dlq.
the class IndexService method createIndex.
/**
* 创建索引
*/
public Object createIndex() {
Object result = "";
try {
// 创建 Mapping
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().field("dynamic", true).startObject("properties").startObject("name").field("type", "text").startObject("fields").startObject("keyword").field("type", "keyword").endObject().endObject().endObject().startObject("address").field("type", "text").startObject("fields").startObject("keyword").field("type", "keyword").endObject().endObject().endObject().startObject("remark").field("type", "text").startObject("fields").startObject("keyword").field("type", "keyword").endObject().endObject().endObject().startObject("age").field("type", "integer").endObject().startObject("salary").field("type", "float").endObject().startObject("birthDate").field("type", "date").field("format", "yyyy-MM-dd").endObject().startObject("createTime").field("type", "date").endObject().endObject().endObject();
// 创建索引配置信息,配置
Settings settings = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).build();
// 新建创建索引请求对象,然后设置索引类型(ES 7.0 将不存在索引类型)和 mapping 与 index 配置
CreateIndexRequest request = new CreateIndexRequest("mydlq-user", settings);
request.mapping("doc", mapping);
// RestHighLevelClient 执行创建索引
CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(request, RequestOptions.DEFAULT);
// 判断是否创建成功
boolean isCreated = createIndexResponse.isAcknowledged();
log.info("是否创建成功:{}", isCreated);
// 根据具体业务逻辑返回不同结果,这里为了方便直接将结果返回
result = isCreated;
} catch (IOException e) {
log.error("", e);
}
return result;
}
use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project elasticsearch-learning-to-rank by o19s.
the class BaseIntegrationTest method createStore.
public void createStore(String name) throws Exception {
assert IndexFeatureStore.isIndexStore(name);
CreateIndexResponse resp = client().execute(CreateIndexAction.INSTANCE, IndexFeatureStore.buildIndexRequest(name)).get();
assertTrue(resp.isAcknowledged());
}
Aggregations