use of org.springframework.data.elasticsearch.core.index.AliasActionParameters in project spring-data-elasticsearch by spring-projects.
the class RequestFactory method indicesAliasesRequest.
public IndicesAliasesRequest indicesAliasesRequest(AliasActions aliasActions) {
IndicesAliasesRequest request = new IndicesAliasesRequest();
aliasActions.getActions().forEach(aliasAction -> {
IndicesAliasesRequest.AliasActions aliasActionsES = null;
if (aliasAction instanceof AliasAction.Add) {
AliasAction.Add add = (AliasAction.Add) aliasAction;
IndicesAliasesRequest.AliasActions addES = IndicesAliasesRequest.AliasActions.add();
AliasActionParameters parameters = add.getParameters();
addES.indices(parameters.getIndices());
addES.aliases(parameters.getAliases());
addES.routing(parameters.getRouting());
addES.indexRouting(parameters.getIndexRouting());
addES.searchRouting(parameters.getSearchRouting());
addES.isHidden(parameters.getHidden());
addES.writeIndex(parameters.getWriteIndex());
Query filterQuery = parameters.getFilterQuery();
if (filterQuery != null) {
elasticsearchConverter.updateQuery(filterQuery, parameters.getFilterQueryClass());
QueryBuilder queryBuilder = getFilter(filterQuery);
if (queryBuilder == null) {
queryBuilder = getQuery(filterQuery);
}
addES.filter(queryBuilder);
}
aliasActionsES = addES;
} else if (aliasAction instanceof AliasAction.Remove) {
AliasAction.Remove remove = (AliasAction.Remove) aliasAction;
IndicesAliasesRequest.AliasActions removeES = IndicesAliasesRequest.AliasActions.remove();
AliasActionParameters parameters = remove.getParameters();
removeES.indices(parameters.getIndices());
removeES.aliases(parameters.getAliases());
aliasActionsES = removeES;
} else if (aliasAction instanceof AliasAction.RemoveIndex) {
AliasAction.RemoveIndex removeIndex = (AliasAction.RemoveIndex) aliasAction;
IndicesAliasesRequest.AliasActions removeIndexES = IndicesAliasesRequest.AliasActions.removeIndex();
AliasActionParameters parameters = removeIndex.getParameters();
removeIndexES.indices(parameters.getIndices()[0]);
aliasActionsES = removeIndexES;
}
if (aliasActionsES != null) {
request.addAliasAction(aliasActionsES);
}
});
return request;
}
use of org.springframework.data.elasticsearch.core.index.AliasActionParameters in project spring-data-elasticsearch by spring-projects.
the class RequestFactory method putIndexTemplateRequest.
public PutIndexTemplateRequest putIndexTemplateRequest(PutTemplateRequest putTemplateRequest) {
PutIndexTemplateRequest request = new PutIndexTemplateRequest(putTemplateRequest.getName()).patterns(Arrays.asList(putTemplateRequest.getIndexPatterns()));
if (putTemplateRequest.getSettings() != null) {
request.settings(putTemplateRequest.getSettings());
}
if (putTemplateRequest.getMappings() != null) {
request.mapping(putTemplateRequest.getMappings());
}
request.order(putTemplateRequest.getOrder()).version(putTemplateRequest.getVersion());
AliasActions aliasActions = putTemplateRequest.getAliasActions();
if (aliasActions != null) {
aliasActions.getActions().forEach(aliasAction -> {
AliasActionParameters parameters = aliasAction.getParameters();
String[] parametersAliases = parameters.getAliases();
if (parametersAliases != null) {
for (String aliasName : parametersAliases) {
Alias alias = new Alias(aliasName);
if (parameters.getRouting() != null) {
alias.routing(parameters.getRouting());
}
if (parameters.getIndexRouting() != null) {
alias.indexRouting(parameters.getIndexRouting());
}
if (parameters.getSearchRouting() != null) {
alias.searchRouting(parameters.getSearchRouting());
}
if (parameters.getHidden() != null) {
alias.isHidden(parameters.getHidden());
}
if (parameters.getWriteIndex() != null) {
alias.writeIndex(parameters.getWriteIndex());
}
Query filterQuery = parameters.getFilterQuery();
if (filterQuery != null) {
elasticsearchConverter.updateQuery(filterQuery, parameters.getFilterQueryClass());
QueryBuilder queryBuilder = getFilter(filterQuery);
if (queryBuilder == null) {
queryBuilder = getQuery(filterQuery);
}
alias.filter(queryBuilder);
}
request.alias(alias);
}
}
});
}
return request;
}
use of org.springframework.data.elasticsearch.core.index.AliasActionParameters in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchTemplateIntegrationTests method shouldReturnInformationListOfAllIndices.
// #1646, #1718
@Test
@DisplayName("should return a list of info for specific index")
void shouldReturnInformationListOfAllIndices() {
String indexName = indexNameProvider.indexName();
String aliasName = indexName + "-alias";
ReactiveIndexOperations indexOps = operations.indexOps(EntityWithSettingsAndMappingsReactive.class);
// beforeEach uses SampleEntity, so recreate the index here
indexOps.delete().then(indexOps.createWithMapping()).block();
AliasActionParameters parameters = AliasActionParameters.builder().withAliases(aliasName).withIndices(indexName).withIsHidden(false).withIsWriteIndex(false).withRouting("indexrouting").withSearchRouting("searchrouting").build();
indexOps.alias(new AliasActions(new AliasAction.Add(parameters))).block();
indexOps.getInformation().as(StepVerifier::create).consumeNextWith(indexInformation -> {
assertThat(indexInformation.getName()).isEqualTo(indexName);
assertThat(indexInformation.getSettings().get("index.number_of_shards")).isEqualTo("1");
assertThat(indexInformation.getSettings().get("index.number_of_replicas")).isEqualTo("0");
assertThat(indexInformation.getSettings().get("index.analysis.analyzer.emailAnalyzer.type")).isEqualTo("custom");
assertThat(indexInformation.getAliases()).hasSize(1);
AliasData aliasData = indexInformation.getAliases().get(0);
assertThat(aliasData.getAlias()).isEqualTo(aliasName);
assertThat(aliasData.isHidden()).isEqualTo(false);
assertThat(aliasData.isWriteIndex()).isEqualTo(false);
assertThat(aliasData.getIndexRouting()).isEqualTo("indexrouting");
assertThat(aliasData.getSearchRouting()).isEqualTo("searchrouting");
String expectedMappings = "{\"properties\":{\"email\":{\"type\":\"text\",\"analyzer\":\"emailAnalyzer\"}}}";
try {
JSONAssert.assertEquals(expectedMappings, indexInformation.getMapping().toJson(), false);
} catch (JSONException e) {
e.printStackTrace();
}
}).verifyComplete();
}
Aggregations