本文整理了Java中org.elasticsearch.client.RestHighLevelClient.indices
方法的一些代码示例,展示了RestHighLevelClient.indices
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RestHighLevelClient.indices
方法的具体详情如下:
包路径:org.elasticsearch.client.RestHighLevelClient
类名称:RestHighLevelClient
方法名:indices
[英]Provides an IndicesClient which can be used to access the Indices API. See Indices API on elastic.co
[中]提供可用于访问索引API的IndicateSClient。见Indices API on elastic.co
代码示例来源:origin: spring-projects/spring-data-elasticsearch
@Override
public void refresh(String indexName) {
Assert.notNull(indexName, "No index defined for refresh()");
try {
// TODO: Do something with the response.
client.indices().refresh(refreshRequest(indexName));
} catch (IOException e) {
throw new ElasticsearchException("failed to refresh index: " + indexName, e);
}
}
代码示例来源:origin: spring-projects/spring-data-elasticsearch
@Override
public boolean indexExists(String indexName) {
GetIndexRequest request = new GetIndexRequest();
request.indices(indexName);
try {
return client.indices().exists(request);
} catch (IOException e) {
throw new ElasticsearchException("Error while for indexExists request: " + request.toString(), e);
}
}
代码示例来源:origin: spring-projects/spring-data-elasticsearch
@Override
public boolean createIndex(String indexName) {
Assert.notNull(indexName, "No index defined for Query");
try {
return client.indices().create(Requests.createIndexRequest(indexName)).isAcknowledged();
} catch (Exception e) {
throw new ElasticsearchException("Failed to create index " + indexName, e);
}
}
代码示例来源:origin: spring-projects/spring-data-elasticsearch
@Override
public boolean deleteIndex(String indexName) {
Assert.notNull(indexName, "No index defined for delete operation");
if (indexExists(indexName)) {
DeleteIndexRequest request = new DeleteIndexRequest(indexName);
try {
return client.indices().delete(request).isAcknowledged();
} catch (IOException e) {
throw new ElasticsearchException("Error while deleting index request: " + request.toString(), e);
}
}
return false;
}
代码示例来源:origin: spring-projects/spring-data-elasticsearch
@Override
public Boolean removeAlias(AliasQuery query) {
Assert.notNull(query.getIndexName(), "No index defined for Alias");
Assert.notNull(query.getAliasName(), "No alias defined");
IndicesAliasesRequest request = new IndicesAliasesRequest();
AliasActions aliasAction = new AliasActions(AliasActions.Type.REMOVE);
request.addAliasAction(aliasAction);
try {
return client.indices().updateAliases(request).isAcknowledged();
} catch (IOException e) {
throw new ElasticsearchException("failed to update aliases with request: " + request, e);
}
}
代码示例来源:origin: spring-projects/spring-data-elasticsearch
@Override
public boolean createIndex(String indexName, Object settings) {
CreateIndexRequest request = new CreateIndexRequest(indexName);
if (settings instanceof String) {
request.settings(String.valueOf(settings), Requests.INDEX_CONTENT_TYPE);
} else if (settings instanceof Map) {
request.settings((Map) settings);
} else if (settings instanceof XContentBuilder) {
request.settings((XContentBuilder) settings);
}
try {
return client.indices().create(request).isAcknowledged();
} catch (IOException e) {
throw new ElasticsearchException("Error for creating index: " + request.toString(), e);
}
}
代码示例来源:origin: spring-projects/spring-data-elasticsearch
@Override
public boolean putMapping(String indexName, String type, Object mapping) {
Assert.notNull(indexName, "No index defined for putMapping()");
Assert.notNull(type, "No type defined for putMapping()");
PutMappingRequest request = new PutMappingRequest(indexName).type(type);
if (mapping instanceof String) {
request.source(String.valueOf(mapping), XContentType.JSON);
} else if (mapping instanceof Map) {
request.source((Map) mapping);
} else if (mapping instanceof XContentBuilder) {
request.source((XContentBuilder) mapping);
}
try {
return client.indices().putMapping(request).isAcknowledged();
} catch (IOException e) {
throw new ElasticsearchException("Failed to put mapping for " + indexName, e);
}
}
代码示例来源:origin: spring-projects/spring-data-elasticsearch
@Override
public Boolean addAlias(AliasQuery query) {
Assert.notNull(query.getIndexName(), "No index defined for Alias");
Assert.notNull(query.getAliasName(), "No alias defined");
final IndicesAliasesRequest.AliasActions aliasAction = IndicesAliasesRequest.AliasActions.add()
.alias(query.getAliasName()).index(query.getIndexName());
if (query.getFilterBuilder() != null) {
aliasAction.filter(query.getFilterBuilder());
} else if (query.getFilter() != null) {
aliasAction.filter(query.getFilter());
} else if (hasText(query.getRouting())) {
aliasAction.routing(query.getRouting());
} else if (hasText(query.getSearchRouting())) {
aliasAction.searchRouting(query.getSearchRouting());
} else if (hasText(query.getIndexRouting())) {
aliasAction.indexRouting(query.getIndexRouting());
}
IndicesAliasesRequest request = new IndicesAliasesRequest();
request.addAliasAction(aliasAction);
try {
return client.indices().updateAliases(request).isAcknowledged();
} catch (IOException e) {
throw new ElasticsearchException("failed to update aliases with request: " + request, e);
}
}
代码示例来源:origin: dadoonet/fscrawler
@Override
public void deleteIndex(String index) throws IOException {
client.indices().delete(new DeleteIndexRequest(index), RequestOptions.DEFAULT);
}
代码示例来源:origin: dadoonet/fscrawler
@Override
public void deleteIndex(String index) throws IOException {
client.indices().delete(new DeleteIndexRequest(index), RequestOptions.DEFAULT);
}
代码示例来源:origin: dadoonet/fscrawler
/**
* Check if an index exists
* @param index index name
* @return true if the index exists, false otherwise
* @throws IOException In case of error
*/
public boolean isExistingIndex(String index) throws IOException {
logger.debug("is existing index [{}]", index);
GetIndexRequest gir = new GetIndexRequest();
gir.indices(index);
return client.indices().exists(gir, RequestOptions.DEFAULT);
}
代码示例来源:origin: dadoonet/fscrawler
/**
* Check if an index exists
* @param index index name
* @return true if the index exists, false otherwise
* @throws IOException In case of error
*/
public boolean isExistingIndex(String index) throws IOException {
logger.debug("is existing index [{}]", index);
GetIndexRequest gir = new GetIndexRequest();
gir.indices(index);
return client.indices().exists(gir, RequestOptions.DEFAULT);
}
代码示例来源:origin: dadoonet/fscrawler
/**
* Refresh an index
* @param index index name
* @throws IOException In case of error
*/
public void refresh(String index) throws IOException {
logger.debug("refresh index [{}]", index);
RefreshRequest request = new RefreshRequest();
if (!isNullOrEmpty(index)) {
request.indices(index);
}
RefreshResponse refresh = client.indices().refresh(request, RequestOptions.DEFAULT);
logger.trace("refresh response: {}", refresh);
}
代码示例来源:origin: dadoonet/fscrawler
/**
* Refresh an index
* @param index index name
* @throws IOException In case of error
*/
public void refresh(String index) throws IOException {
logger.debug("refresh index [{}]", index);
RefreshRequest request = new RefreshRequest();
if (!isNullOrEmpty(index)) {
request.indices(index);
}
RefreshResponse refresh = client.indices().refresh(request, RequestOptions.DEFAULT);
logger.trace("refresh response: {}", refresh);
}
代码示例来源:origin: tomoya92/pybbs
public boolean deleteIndex() {
try {
if (this.instance() == null) return false;
DeleteIndexRequest request = new DeleteIndexRequest(name);
request.indicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN);
AcknowledgedResponse response = client.indices().delete(request, RequestOptions.DEFAULT);
return response.isAcknowledged();
} catch (IOException e) {
log.error(e.getMessage());
return false;
}
}
代码示例来源:origin: dadoonet/fscrawler
/**
* Create an index
* @param index index name
* @param ignoreErrors don't fail if the index already exists
* @param indexSettings index settings if any
* @throws IOException In case of error
*/
public void createIndex(String index, boolean ignoreErrors, String indexSettings) throws IOException {
logger.debug("create index [{}]", index);
logger.trace("index settings: [{}]", indexSettings);
CreateIndexRequest cir = new CreateIndexRequest(index);
if (!isNullOrEmpty(indexSettings)) {
cir.source(indexSettings, XContentType.JSON);
}
try {
client.indices().create(cir, RequestOptions.DEFAULT);
} catch (ElasticsearchStatusException e) {
if (e.getMessage().contains("resource_already_exists_exception") && !ignoreErrors) {
throw new RuntimeException("index already exists");
}
}
}
代码示例来源:origin: tomoya92/pybbs
public boolean createIndex(String type, XContentBuilder mappingBuilder) {
try {
if (this.instance() == null) return false;
CreateIndexRequest request = new CreateIndexRequest(name);
request.settings(Settings.builder()
.put("index.number_of_shards", 1)
.put("index.number_of_shards", 5));
if (mappingBuilder != null) request.mapping(type, mappingBuilder);
CreateIndexResponse response = this.client.indices().create(request, RequestOptions.DEFAULT);
return response.isAcknowledged();
} catch (IOException e) {
log.error(e.getMessage());
return false;
}
}
代码示例来源:origin: dadoonet/fscrawler
/**
* Create an index
* @param index index name
* @param ignoreErrors don't fail if the index already exists
* @param indexSettings index settings if any
* @throws IOException In case of error
*/
public void createIndex(String index, boolean ignoreErrors, String indexSettings) throws IOException {
logger.debug("create index [{}]", index);
logger.trace("index settings: [{}]", indexSettings);
CreateIndexRequest cir = new CreateIndexRequest(index);
if (!isNullOrEmpty(indexSettings)) {
cir.source(indexSettings, XContentType.JSON);
}
try {
client.indices().create(cir, RequestOptions.DEFAULT);
} catch (ElasticsearchStatusException e) {
if (e.getMessage().contains("resource_already_exists_exception") && !ignoreErrors) {
throw new RuntimeException("index already exists");
}
}
}
代码示例来源:origin: tomoya92/pybbs
public boolean existIndex() {
try {
if (this.instance() == null) return false;
GetIndexRequest request = new GetIndexRequest();
request.indices(name);
request.local(false);
request.humanReadable(true);
return client.indices().exists(request, RequestOptions.DEFAULT);
} catch (IOException e) {
log.error(e.getMessage());
return false;
}
}
代码示例来源:origin: dqeasycloud/easy-cloud
public boolean existsIndex(String indexName, String type) throws IOException {
try {
GetIndexRequest request = new GetIndexRequest();
request.indices(indexName);
return client.indices().exists(request);
} catch (ElasticsearchException exception) {
if (exception.status() == RestStatus.NOT_FOUND) {
}
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!