즐겁게/elasticsearch-8

PutIndicesSettingsRequest를 이용한 인덱스 Settings 값 변경

파이브빈즈 2022. 10. 10. 17:05

PutIndicesSettingsRequest를 이용하여 IndexSetting을 변경할수 있음

단, numberOfShards는 변경이 불가

public void updateIndexSettings() {
	ElasticsearchClient client = null;
	try {
		// Index name to delete
		String indexName = "test-Index";

		int replicas = 0;
		int maxResultWindows = 10000;
		String refreshInterval = "5s";

		// 참고로 Shard 개수는 변경이 불가
		
		IndexSettings indexSettings = new IndexSettings.Builder()
				// Replica 개수 
				.numberOfReplicas(String.valueOf(replicas))
				// Max result window 수
				.maxResultWindow((int)maxResultWindows)
				// Refresh interval(초)
				.refreshInterval(new Time.Builder().time(refreshInterval).build())
				.build();

		// ElasticSearchClient
		client = ElasticClient.getInstacne();

		PutIndicesSettingsRequest request = new PutIndicesSettingsRequest.Builder()
        		.index(indexName).settings(indexSettings).build();
		PutIndicesSettingsResponse response = client.indices().putSettings(request);

		System.out.println("updateIndexSettings result : " + response.acknowledged());

	} catch (IOException e) {
		e.printStackTrace();
	} finally {
		ElasticClient.close();
	}
}