use of org.opensearch.common.settings.Settings in project OpenSearch by opensearch-project.
the class IndicesClientIT method testClone.
@SuppressWarnings("unchecked")
public void testClone() throws IOException {
createIndex("source", Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).put("index.number_of_routing_shards", 4).build());
updateIndexSettings("source", Settings.builder().put("index.blocks.write", true));
ResizeRequest resizeRequest = new ResizeRequest("target", "source");
resizeRequest.setResizeType(ResizeType.CLONE);
Settings targetSettings = Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).build();
resizeRequest.setTargetIndex(new org.opensearch.action.admin.indices.create.CreateIndexRequest("target").settings(targetSettings).alias(new Alias("alias")));
ResizeResponse resizeResponse = execute(resizeRequest, highLevelClient().indices()::clone, highLevelClient().indices()::cloneAsync);
assertTrue(resizeResponse.isAcknowledged());
assertTrue(resizeResponse.isShardsAcknowledged());
Map<String, Object> getIndexResponse = getAsMap("target");
Map<String, Object> indexSettings = (Map<String, Object>) XContentMapValues.extractValue("target.settings.index", getIndexResponse);
assertNotNull(indexSettings);
assertEquals("2", indexSettings.get("number_of_shards"));
assertEquals("0", indexSettings.get("number_of_replicas"));
Map<String, Object> aliasData = (Map<String, Object>) XContentMapValues.extractValue("target.aliases.alias", getIndexResponse);
assertNotNull(aliasData);
}
use of org.opensearch.common.settings.Settings in project OpenSearch by opensearch-project.
the class IndicesClientDocumentationIT method testSimulateIndexTemplate.
public void testSimulateIndexTemplate() throws Exception {
RestHighLevelClient client = highLevelClient();
{
// <1>
PutComposableIndexTemplateRequest request = new PutComposableIndexTemplateRequest().name("my-template");
Template template = new Template(Settings.builder().put("index.number_of_replicas", 3).build(), null, null);
ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(Arrays.asList("pattern-1", "log-*"), template, null, null, null, null);
request.indexTemplate(composableIndexTemplate);
assertTrue(client.indices().putIndexTemplate(request, RequestOptions.DEFAULT).isAcknowledged());
}
// tag::simulate-index-template-request
// <1>
SimulateIndexTemplateRequest simulateRequest = new SimulateIndexTemplateRequest("log-000001");
PutComposableIndexTemplateRequest newIndexTemplateRequest = new PutComposableIndexTemplateRequest().name("used-for-simulation");
Settings settings = Settings.builder().put("index.number_of_shards", 6).build();
// <2>
Template template = new Template(settings, null, null);
ComposableIndexTemplate composableIndexTemplate = new ComposableIndexTemplate(Arrays.asList("log-*"), template, null, 90L, null, null);
newIndexTemplateRequest.indexTemplate(composableIndexTemplate);
// <2>
simulateRequest.indexTemplateV2Request(newIndexTemplateRequest);
// end::simulate-index-template-request
// tag::simulate-index-template-response
SimulateIndexTemplateResponse simulateIndexTemplateResponse = client.indices().simulateIndexTemplate(simulateRequest, RequestOptions.DEFAULT);
// <1>
assertThat(simulateIndexTemplateResponse.resolvedTemplate().settings().get("index.number_of_shards"), is("6"));
assertThat(simulateIndexTemplateResponse.overlappingTemplates().get("my-template"), // <2>
containsInAnyOrder("pattern-1", "log-*"));
// end::simulate-index-template-response
// tag::simulate-index-template-execute-listener
ActionListener<SimulateIndexTemplateResponse> listener = new ActionListener<SimulateIndexTemplateResponse>() {
@Override
public void onResponse(SimulateIndexTemplateResponse response) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::simulate-index-template-execute-listener
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::simulate-index-template-execute-async
// <1>
client.indices().simulateIndexTemplateAsync(simulateRequest, RequestOptions.DEFAULT, listener);
// end::simulate-index-template-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
use of org.opensearch.common.settings.Settings in project OpenSearch by opensearch-project.
the class IndicesClientDocumentationIT method testIndexPutSettings.
@SuppressWarnings("unused")
public void testIndexPutSettings() throws Exception {
RestHighLevelClient client = highLevelClient();
{
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
}
// tag::indices-put-settings-request
// <1>
UpdateSettingsRequest request = new UpdateSettingsRequest("index1");
UpdateSettingsRequest requestMultiple = // <2>
new UpdateSettingsRequest("index1", "index2");
// <3>
UpdateSettingsRequest requestAll = new UpdateSettingsRequest();
// end::indices-put-settings-request
// tag::indices-put-settings-create-settings
String settingKey = "index.number_of_replicas";
int settingValue = 0;
Settings settings = Settings.builder().put(settingKey, settingValue).build();
// end::indices-put-settings-create-settings
// tag::indices-put-settings-request-index-settings
request.settings(settings);
// end::indices-put-settings-request-index-settings
{
// tag::indices-put-settings-settings-builder
Settings.Builder settingsBuilder = Settings.builder().put(settingKey, settingValue);
// <1>
request.settings(settingsBuilder);
// end::indices-put-settings-settings-builder
}
{
// tag::indices-put-settings-settings-map
Map<String, Object> map = new HashMap<>();
map.put(settingKey, settingValue);
// <1>
request.settings(map);
// end::indices-put-settings-settings-map
}
{
// tag::indices-put-settings-settings-source
request.settings("{\"index.number_of_replicas\": \"2\"}", // <1>
XContentType.JSON);
// end::indices-put-settings-settings-source
}
// tag::indices-put-settings-request-preserveExisting
// <1>
request.setPreserveExisting(false);
// end::indices-put-settings-request-preserveExisting
// tag::indices-put-settings-request-timeout
// <1>
request.timeout(TimeValue.timeValueMinutes(2));
// <2>
request.timeout("2m");
// end::indices-put-settings-request-timeout
// tag::indices-put-settings-request-masterTimeout
// <1>
request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
// <2>
request.masterNodeTimeout("1m");
// end::indices-put-settings-request-masterTimeout
// tag::indices-put-settings-request-indicesOptions
// <1>
request.indicesOptions(IndicesOptions.lenientExpandOpen());
// end::indices-put-settings-request-indicesOptions
// tag::indices-put-settings-execute
AcknowledgedResponse updateSettingsResponse = client.indices().putSettings(request, RequestOptions.DEFAULT);
// end::indices-put-settings-execute
// tag::indices-put-settings-response
// <1>
boolean acknowledged = updateSettingsResponse.isAcknowledged();
// end::indices-put-settings-response
assertTrue(acknowledged);
// tag::indices-put-settings-execute-listener
ActionListener<AcknowledgedResponse> listener = new ActionListener<AcknowledgedResponse>() {
@Override
public void onResponse(AcknowledgedResponse updateSettingsResponse) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::indices-put-settings-execute-listener
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::indices-put-settings-execute-async
// <1>
client.indices().putSettingsAsync(request, RequestOptions.DEFAULT, listener);
// end::indices-put-settings-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
use of org.opensearch.common.settings.Settings in project OpenSearch by opensearch-project.
the class UpdateByQueryIT method testUpdateByQueryConflict.
public void testUpdateByQueryConflict() throws IOException {
final String index = "testupdatebyqueryconflict";
final Settings settings = Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).build();
createIndex(index, settings);
final BulkRequest bulkRequest = new BulkRequest().add(new IndexRequest(index).id("1").source(Collections.singletonMap("foo", "bar"), XContentType.JSON)).add(new IndexRequest(index).id("2").source(Collections.singletonMap("foo", "bar"), XContentType.JSON)).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
assertThat(highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT).status(), equalTo(RestStatus.OK));
putConflictPipeline();
final UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest();
updateByQueryRequest.indices(index);
updateByQueryRequest.setRefresh(true);
updateByQueryRequest.setPipeline(CONFLICT_PIPELINE_ID);
final BulkByScrollResponse response = highLevelClient().updateByQuery(updateByQueryRequest, RequestOptions.DEFAULT);
assertThat(response.getVersionConflicts(), equalTo(1L));
assertThat(response.getSearchFailures(), empty());
assertThat(response.getBulkFailures(), hasSize(1));
assertThat(response.getBulkFailures().stream().map(BulkItemResponse.Failure::getMessage).collect(Collectors.toSet()), everyItem(containsString("version conflict")));
assertThat(response.getTotal(), equalTo(2L));
assertThat(response.getCreated(), equalTo(0L));
assertThat(response.getUpdated(), equalTo(1L));
assertThat(response.getDeleted(), equalTo(0L));
assertThat(response.getNoops(), equalTo(0L));
assertThat(response.getBatches(), equalTo(1));
assertTrue(response.getTook().getMillis() > 0);
}
use of org.opensearch.common.settings.Settings in project OpenSearch by opensearch-project.
the class GetIndexResponseTests method createServerTestInstance.
@Override
protected org.opensearch.action.admin.indices.get.GetIndexResponse createServerTestInstance(XContentType xContentType) {
String[] indices = generateRandomStringArray(5, 5, false, false);
ImmutableOpenMap.Builder<String, MappingMetadata> mappings = ImmutableOpenMap.builder();
ImmutableOpenMap.Builder<String, List<AliasMetadata>> aliases = ImmutableOpenMap.builder();
ImmutableOpenMap.Builder<String, Settings> settings = ImmutableOpenMap.builder();
ImmutableOpenMap.Builder<String, Settings> defaultSettings = ImmutableOpenMap.builder();
ImmutableOpenMap.Builder<String, String> dataStreams = ImmutableOpenMap.builder();
IndexScopedSettings indexScopedSettings = IndexScopedSettings.DEFAULT_SCOPED_SETTINGS;
boolean includeDefaults = randomBoolean();
for (String index : indices) {
mappings.put(index, createMappingsForIndex());
List<AliasMetadata> aliasMetadataList = new ArrayList<>();
int aliasesNum = randomIntBetween(0, 3);
for (int i = 0; i < aliasesNum; i++) {
aliasMetadataList.add(GetAliasesResponseTests.createAliasMetadata());
}
CollectionUtil.timSort(aliasMetadataList, Comparator.comparing(AliasMetadata::alias));
aliases.put(index, Collections.unmodifiableList(aliasMetadataList));
Settings.Builder builder = Settings.builder();
builder.put(RandomCreateIndexGenerator.randomIndexSettings());
settings.put(index, builder.build());
if (includeDefaults) {
defaultSettings.put(index, indexScopedSettings.diff(settings.get(index), Settings.EMPTY));
}
if (randomBoolean()) {
dataStreams.put(index, randomAlphaOfLength(5).toLowerCase(Locale.ROOT));
}
}
return new org.opensearch.action.admin.indices.get.GetIndexResponse(indices, mappings.build(), aliases.build(), settings.build(), defaultSettings.build(), dataStreams.build());
}
Aggregations