use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest in project snow-owl by b2ihealthcare.
the class EsIndexAdmin method refresh.
public void refresh(Set<DocumentMapping> typesToRefresh) {
if (!CompareUtils.isEmpty(typesToRefresh)) {
final String[] indicesToRefresh;
synchronized (typesToRefresh) {
indicesToRefresh = typesToRefresh.stream().map(this::getTypeIndex).distinct().toArray(String[]::new);
}
if (log.isTraceEnabled()) {
log.trace("Refreshing indexes '{}'", Arrays.toString(indicesToRefresh));
}
try {
final RefreshRequest refreshRequest = new RefreshRequest(indicesToRefresh);
final RefreshResponse refreshResponse = client().indices().refresh(refreshRequest);
if (RestStatus.OK != refreshResponse.getStatus() && log.isErrorEnabled()) {
log.error("Index refresh request of '{}' returned with status {}", Arrays.toString(indicesToRefresh), refreshResponse.getStatus());
}
} catch (Exception e) {
throw new IndexException(String.format("Failed to refresh ES indexes '%s'.", Arrays.toString(indicesToRefresh)), e);
}
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest in project ranger by apache.
the class RequestUtils method getIndexFromRequest.
// To support all kinds of request in elasticsearch
public static <Request extends ActionRequest> List<String> getIndexFromRequest(Request request) {
List<String> indexs = new ArrayList<>();
if (request instanceof SingleShardRequest) {
indexs.add(((SingleShardRequest<?>) request).index());
return indexs;
}
if (request instanceof ReplicationRequest) {
indexs.add(((ReplicationRequest<?>) request).index());
return indexs;
}
if (request instanceof InstanceShardOperationRequest) {
indexs.add(((InstanceShardOperationRequest<?>) request).index());
return indexs;
}
if (request instanceof CreateIndexRequest) {
indexs.add(((CreateIndexRequest) request).index());
return indexs;
}
if (request instanceof PutMappingRequest) {
if (((PutMappingRequest) request).getConcreteIndex() != null) {
indexs.add(((PutMappingRequest) request).getConcreteIndex().getName());
return indexs;
} else {
return Arrays.asList(((PutMappingRequest) request).indices());
}
}
if (request instanceof SearchRequest) {
return Arrays.asList(((SearchRequest) request).indices());
}
if (request instanceof IndicesStatsRequest) {
return Arrays.asList(((IndicesStatsRequest) request).indices());
}
if (request instanceof OpenIndexRequest) {
return Arrays.asList(((OpenIndexRequest) request).indices());
}
if (request instanceof DeleteIndexRequest) {
return Arrays.asList(((DeleteIndexRequest) request).indices());
}
if (request instanceof BulkRequest) {
@SuppressWarnings("rawtypes") List<DocWriteRequest<?>> requests = ((BulkRequest) request).requests();
if (CollectionUtils.isNotEmpty(requests)) {
for (DocWriteRequest<?> docWriteRequest : requests) {
indexs.add(docWriteRequest.index());
}
return indexs;
}
}
if (request instanceof MultiGetRequest) {
List<Item> items = ((MultiGetRequest) request).getItems();
if (CollectionUtils.isNotEmpty(items)) {
for (Item item : items) {
indexs.add(item.index());
}
return indexs;
}
}
if (request instanceof GetMappingsRequest) {
return Arrays.asList(((GetMappingsRequest) request).indices());
}
if (request instanceof GetSettingsRequest) {
return Arrays.asList(((GetSettingsRequest) request).indices());
}
if (request instanceof IndicesExistsRequest) {
return Arrays.asList(((IndicesExistsRequest) request).indices());
}
if (request instanceof GetAliasesRequest) {
return Arrays.asList(((GetAliasesRequest) request).indices());
}
if (request instanceof GetIndexRequest) {
return Arrays.asList(((GetIndexRequest) request).indices());
}
if (request instanceof GetFieldMappingsRequest) {
return Arrays.asList(((GetFieldMappingsRequest) request).indices());
}
if (request instanceof TypesExistsRequest) {
return Arrays.asList(((TypesExistsRequest) request).indices());
}
if (request instanceof ValidateQueryRequest) {
return Arrays.asList(((ValidateQueryRequest) request).indices());
}
if (request instanceof RecoveryRequest) {
return Arrays.asList(((RecoveryRequest) request).indices());
}
if (request instanceof IndicesSegmentsRequest) {
return Arrays.asList(((IndicesSegmentsRequest) request).indices());
}
if (request instanceof IndicesShardStoresRequest) {
return Arrays.asList(((IndicesShardStoresRequest) request).indices());
}
if (request instanceof UpgradeStatusRequest) {
return Arrays.asList(((UpgradeStatusRequest) request).indices());
}
if (request instanceof ClusterSearchShardsRequest) {
return Arrays.asList(((ClusterSearchShardsRequest) request).indices());
}
if (request instanceof IndicesAliasesRequest) {
List<IndicesAliasesRequest.AliasActions> aliasActions = ((IndicesAliasesRequest) request).getAliasActions();
if (CollectionUtils.isNotEmpty(aliasActions)) {
for (IndicesAliasesRequest.AliasActions action : aliasActions) {
indexs.addAll(Arrays.asList(action.indices()));
}
return indexs;
}
}
if (request instanceof ClearIndicesCacheRequest) {
return Arrays.asList(((ClearIndicesCacheRequest) request).indices());
}
if (request instanceof CloseIndexRequest) {
return Arrays.asList(((CloseIndexRequest) request).indices());
}
if (request instanceof FlushRequest) {
return Arrays.asList(((FlushRequest) request).indices());
}
if (request instanceof SyncedFlushRequest) {
return Arrays.asList(((SyncedFlushRequest) request).indices());
}
if (request instanceof ForceMergeRequest) {
return Arrays.asList(((ForceMergeRequest) request).indices());
}
if (request instanceof RefreshRequest) {
return Arrays.asList(((RefreshRequest) request).indices());
}
if (request instanceof RolloverRequest) {
return Arrays.asList(((RolloverRequest) request).indices());
}
if (request instanceof UpdateSettingsRequest) {
return Arrays.asList(((UpdateSettingsRequest) request).indices());
}
if (request instanceof ResizeRequest) {
return Arrays.asList(((ResizeRequest) request).indices());
}
if (request instanceof DeleteIndexTemplateRequest) {
indexs.add(((DeleteIndexTemplateRequest) request).name());
return indexs;
}
if (request instanceof GetIndexTemplatesRequest) {
return Arrays.asList(((GetIndexTemplatesRequest) request).names());
}
if (request instanceof PutIndexTemplateRequest) {
indexs.add(((PutIndexTemplateRequest) request).name());
return indexs;
}
if (request instanceof UpgradeRequest) {
return Arrays.asList(((UpgradeRequest) request).indices());
}
if (request instanceof FieldCapabilitiesRequest) {
return Arrays.asList(((FieldCapabilitiesRequest) request).indices());
}
if (request instanceof MultiSearchRequest) {
List<SearchRequest> searchRequests = ((MultiSearchRequest) request).requests();
if (CollectionUtils.isNotEmpty(searchRequests)) {
for (SearchRequest singleRequest : searchRequests) {
indexs.addAll(Arrays.asList(singleRequest.indices()));
}
return indexs;
}
}
if (request instanceof MultiTermVectorsRequest) {
List<TermVectorsRequest> termVectorsRequests = ((MultiTermVectorsRequest) request).getRequests();
if (CollectionUtils.isNotEmpty(termVectorsRequests)) {
for (TermVectorsRequest singleRequest : termVectorsRequests) {
indexs.addAll(Arrays.asList(singleRequest.indices()));
}
return indexs;
}
}
if (request instanceof UpdateByQueryRequest) {
return Arrays.asList(((UpdateByQueryRequest) request).indices());
}
if (request instanceof DeleteByQueryRequest) {
return Arrays.asList(((DeleteByQueryRequest) request).indices());
}
if (request instanceof ReindexRequest) {
indexs.addAll(Arrays.asList(((ReindexRequest) request).getSearchRequest().indices()));
indexs.addAll(Arrays.asList(((ReindexRequest) request).getDestination().indices()));
return indexs;
}
// ClearScrollRequest does not carry any index, so return empty List
if (request instanceof ClearScrollRequest) {
return indexs;
}
// No matched request type to find specific index , set default value *
indexs.add("*");
return indexs;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest in project drill by apache.
the class ElasticComplexTypesTest method prepareData.
private static void prepareData() throws IOException {
restHighLevelClient = new RestHighLevelClient(RestClient.builder(HttpHost.create(HOST)));
String indexName = "arr";
indexNames.add(indexName);
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("string_arr", Arrays.asList("a", "b", "c", "d"));
builder.field("int_arr", Arrays.asList(1, 2, 3, 4, 0));
builder.field("nest_int_arr", Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3, 4, 0)));
builder.endObject();
IndexRequest indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
restHighLevelClient.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT);
indexName = "map";
indexNames.add(indexName);
createIndexRequest = new CreateIndexRequest(indexName);
restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("prim_field", 321);
builder.field("nest_field", ImmutableMap.of("a", 123, "b", "abc"));
builder.field("more_nest_field", ImmutableMap.of("a", 123, "b", ImmutableMap.of("c", "abc")));
builder.field("map_arr", Collections.singletonList(ImmutableMap.of("a", 123, "b", ImmutableMap.of("c", "abc"))));
builder.endObject();
indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
restHighLevelClient.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest in project drill by apache.
the class ElasticSearchPlanTest method prepareData.
private static void prepareData() throws IOException {
restHighLevelClient = new RestHighLevelClient(RestClient.builder(HttpHost.create(HOST)));
indexName = "nation";
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("n_nationkey", 0);
builder.field("n_name", "ALGERIA");
builder.field("n_regionkey", 1);
builder.endObject();
IndexRequest indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
restHighLevelClient.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.refresh.RefreshRequest in project drill by apache.
the class ElasticSearchQueryTest method prepareData.
private static void prepareData() throws IOException {
restHighLevelClient = new RestHighLevelClient(RestClient.builder(HttpHost.create(HOST)));
indexName = "employee";
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("employee_id", 1);
builder.field("full_name", "Sheri Nowmer");
builder.field("first_name", "Sheri");
builder.field("last_name", "Nowmer");
builder.field("position_id", 1);
builder.field("position_title", "President");
builder.field("store_id", 0);
builder.field("department_id", 1);
builder.field("birth_date", "1961-08-26");
builder.field("hire_date", "1994-12-01 00:00:00.0");
builder.field("salary", 80000.0);
builder.field("supervisor_id", 0);
builder.field("education_level", "Graduate Degree");
builder.field("marital_status", "S");
builder.field("gender", "F");
builder.field("management_role", "Senior Management");
builder.endObject();
IndexRequest indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("employee_id", 2);
builder.field("full_name", "Derrick Whelply");
builder.field("first_name", "Derrick");
builder.field("last_name", "Whelply");
builder.field("position_id", 2);
builder.field("position_title", "VP Country Manager");
builder.field("store_id", 0);
builder.field("department_id", 1);
builder.field("birth_date", "1915-07-03");
builder.field("hire_date", "1994-12-01 00:00:00.0");
builder.field("salary", 40000.0);
builder.field("supervisor_id", 1);
builder.field("education_level", "Graduate Degree");
builder.field("marital_status", "M");
builder.field("gender", "M");
builder.field("management_role", "Senior Management");
builder.endObject();
indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("employee_id", 4);
builder.field("full_name", "Michael Spence");
builder.field("first_name", "Michael");
builder.field("last_name", "Spence");
builder.field("position_id", 2);
builder.field("position_title", "VP Country Manager");
builder.field("store_id", 0);
builder.field("department_id", 1);
builder.field("birth_date", "1969-06-20");
builder.field("hire_date", "1998-01-01 00:00:00.0");
builder.field("salary", 40000.0);
builder.field("supervisor_id", 1);
builder.field("education_level", "Graduate Degree");
builder.field("marital_status", "S");
builder.field("gender", "M");
builder.field("management_role", "Senior Management");
builder.endObject();
indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("employee_id", 5);
builder.field("full_name", "Maya Gutierrez");
builder.field("first_name", "Maya");
builder.field("last_name", "Gutierrez");
builder.field("position_id", 2);
builder.field("position_title", "VP Country Manager");
builder.field("store_id", 0);
builder.field("department_id", 1);
builder.field("birth_date", "1951-05-10");
builder.field("hire_date", "1998-01-01 00:00:00.0");
builder.field("salary", 35000.0);
builder.field("supervisor_id", 1);
builder.field("education_level", "Bachelors Degree");
builder.field("marital_status", "M");
builder.field("gender", "F");
builder.field("management_role", "Senior Management");
builder.endObject();
indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("employee_id", 6);
builder.field("full_name", "Roberta Damstra");
builder.field("first_name", "Roberta");
builder.field("last_name", "Damstra");
builder.field("position_id", 3);
builder.field("position_title", "VP Information Systems");
builder.field("store_id", 0);
builder.field("department_id", 2);
builder.field("birth_date", "1942-10-08");
builder.field("hire_date", "1994-12-01 00:00:00.0");
builder.field("salary", 25000.0);
builder.field("supervisor_id", 1);
builder.field("education_level", "Bachelors Degree");
builder.field("marital_status", "M");
builder.field("gender", "F");
builder.field("management_role", "Senior Management");
builder.endObject();
indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("employee_id", 7);
builder.field("full_name", "Rebecca Kanagaki");
builder.field("first_name", "Rebecca");
builder.field("last_name", "Kanagaki");
builder.field("position_id", 4);
builder.field("position_title", "VP Human Resources");
builder.field("store_id", 0);
builder.field("department_id", 3);
builder.field("birth_date", "1949-03-27");
builder.field("hire_date", "1994-12-01 00:00:00.0");
builder.field("salary", 15000.0);
builder.field("supervisor_id", 1);
builder.field("education_level", "Bachelors Degree");
builder.field("marital_status", "M");
builder.field("gender", "F");
builder.field("management_role", "Senior Management");
builder.endObject();
indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("employee_id", 8);
builder.field("full_name", "Kim Brunner");
builder.field("first_name", "Kim");
builder.field("last_name", "Brunner");
builder.field("position_id", 11);
builder.field("position_title", "Store Manager");
builder.field("store_id", 9);
builder.field("department_id", 11);
builder.field("birth_date", "1922-08-10");
builder.field("hire_date", "1998-01-01 00:00:00.0");
builder.field("salary", 10000.0);
builder.field("supervisor_id", 5);
builder.field("education_level", "Bachelors Degree");
builder.field("marital_status", "S");
builder.field("gender", "F");
builder.field("management_role", "Store Management");
builder.endObject();
indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("employee_id", 9);
builder.field("full_name", "Brenda Blumberg");
builder.field("first_name", "Brenda");
builder.field("last_name", "Blumberg");
builder.field("position_id", 11);
builder.field("position_title", "Store Manager");
builder.field("store_id", 21);
builder.field("department_id", 11);
builder.field("birth_date", "1979-06-23");
builder.field("hire_date", "1998-01-01 00:00:00.0");
builder.field("salary", 17000.0);
builder.field("supervisor_id", 5);
builder.field("education_level", "Graduate Degree");
builder.field("marital_status", "M");
builder.field("gender", "F");
builder.field("management_role", "Store Management");
builder.endObject();
indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("employee_id", 10);
builder.field("full_name", "Darren Stanz");
builder.field("first_name", "Darren");
builder.field("last_name", "Stanz");
builder.field("position_id", 5);
builder.field("position_title", "VP Finance");
builder.field("store_id", 0);
builder.field("department_id", 5);
builder.field("birth_date", "1949-08-26");
builder.field("hire_date", "1994-12-01 00:00:00.0");
builder.field("salary", 50000.0);
builder.field("supervisor_id", 1);
builder.field("education_level", "Partial College");
builder.field("marital_status", "M");
builder.field("gender", "M");
builder.field("management_role", "Senior Management");
builder.endObject();
indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("employee_id", 11);
builder.field("full_name", "Jonathan Murraiin");
builder.field("first_name", "Jonathan");
builder.field("last_name", "Murraiin");
builder.field("position_id", 11);
builder.field("position_title", "Store Manager");
builder.field("store_id", 1);
builder.field("department_id", 11);
builder.field("birth_date", "1967-06-20");
builder.field("hire_date", "1998-01-01 00:00:00.0");
builder.field("salary", 15000.0);
builder.field("supervisor_id", 5);
builder.field("education_level", "Graduate Degree");
builder.field("marital_status", "S");
builder.field("gender", "M");
builder.field("management_role", "Store Management");
builder.endObject();
indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
restHighLevelClient.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT);
}
Aggregations