Skip to content

Commit 90a1f2c

Browse files
committed
Merge remote-tracking branch 'origin/master' into pr/30367
* origin/master: (39 commits) Docs: fix changelog merge Fix line length violation in cache tests Add stricter geohash parsing (elastic#30376) Add failing test for core cache deadlock [DOCS] convert forcemerge snippet Update forcemerge.asciidoc (elastic#30113) Added zentity to the list of API extension plugins (elastic#29143) Fix the search request default operation behavior doc (elastic#29302) (elastic#29405) Watcher: Mark watcher as started only after loading watches (elastic#30403) Pass the task to broadcast actions (elastic#29672) Disable REST default settings testing until elastic#29229 is back-ported Correct wording in log message (elastic#30336) Do not fail snapshot when deleting a missing snapshotted file (elastic#30332) AwaitsFix testCreateShrinkIndexToN DOCS: Correct mapping tags in put-template api DOCS: Fix broken link in the put index template api Add put index template api to high level rest client (elastic#30400) Relax testAckedIndexing to allow document updating [Docs] Add snippets for POS stop tags default value Move respect accept header on no handler to 6.3.1 ...
2 parents 4e3cadf + 44c6dcf commit 90a1f2c

File tree

140 files changed

+4250
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+4250
-324
lines changed

buildSrc/version.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
elasticsearch = 7.0.0-alpha1
2-
lucene = 7.3.0
2+
lucene = 7.4.0-snapshot-1ed95c097b
33

44
# optional dependencies
55
spatial4j = 0.7

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java

+48
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@
4343
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
4444
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
4545
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
46+
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
47+
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
4648
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
4749
import org.elasticsearch.action.admin.indices.rollover.RolloverResponse;
4850
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
4951
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse;
5052
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
5153
import org.elasticsearch.action.admin.indices.shrink.ResizeResponse;
54+
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
55+
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
5256

5357
import java.io.IOException;
5458
import java.util.Collections;
@@ -265,6 +269,28 @@ public void flushAsync(FlushRequest flushRequest, ActionListener<FlushResponse>
265269
listener, emptySet(), headers);
266270
}
267271

272+
/**
273+
* Retrieve the settings of one or more indices
274+
* <p>
275+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-settings.html">
276+
* Indices Get Settings API on elastic.co</a>
277+
*/
278+
public GetSettingsResponse getSettings(GetSettingsRequest getSettingsRequest, Header... headers) throws IOException {
279+
return restHighLevelClient.performRequestAndParseEntity(getSettingsRequest, RequestConverters::getSettings,
280+
GetSettingsResponse::fromXContent, emptySet(), headers);
281+
}
282+
283+
/**
284+
* Asynchronously retrieve the settings of one or more indices
285+
* <p>
286+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-settings.html">
287+
* Indices Get Settings API on elastic.co</a>
288+
*/
289+
public void getSettingsAsync(GetSettingsRequest getSettingsRequest, ActionListener<GetSettingsResponse> listener, Header... headers) {
290+
restHighLevelClient.performRequestAsyncAndParseEntity(getSettingsRequest, RequestConverters::getSettings,
291+
GetSettingsResponse::fromXContent, listener, emptySet(), headers);
292+
}
293+
268294
/**
269295
* Force merge one or more indices using the Force Merge API
270296
* <p>
@@ -432,4 +458,26 @@ public void putSettingsAsync(UpdateSettingsRequest updateSettingsRequest, Action
432458
UpdateSettingsResponse::fromXContent, listener, emptySet(), headers);
433459
}
434460

461+
/**
462+
* Puts an index template using the Index Templates API
463+
* <p>
464+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
465+
* on elastic.co</a>
466+
*/
467+
public PutIndexTemplateResponse putTemplate(PutIndexTemplateRequest putIndexTemplateRequest, Header... headers) throws IOException {
468+
return restHighLevelClient.performRequestAndParseEntity(putIndexTemplateRequest, RequestConverters::putTemplate,
469+
PutIndexTemplateResponse::fromXContent, emptySet(), headers);
470+
}
471+
472+
/**
473+
* Asynchronously puts an index template using the Index Templates API
474+
* <p>
475+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
476+
* on elastic.co</a>
477+
*/
478+
public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest,
479+
ActionListener<PutIndexTemplateResponse> listener, Header... headers) {
480+
restHighLevelClient.performRequestAsyncAndParseEntity(putIndexTemplateRequest, RequestConverters::putTemplate,
481+
PutIndexTemplateResponse::fromXContent, listener, emptySet(), headers);
482+
}
435483
}

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

+33-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@
4444
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
4545
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
4646
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
47+
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
4748
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
4849
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
50+
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
4951
import org.elasticsearch.action.bulk.BulkRequest;
5052
import org.elasticsearch.action.delete.DeleteRequest;
5153
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest;
@@ -76,7 +78,6 @@
7678
import org.elasticsearch.common.xcontent.XContentType;
7779
import org.elasticsearch.index.VersionType;
7880
import org.elasticsearch.index.rankeval.RankEvalRequest;
79-
import org.elasticsearch.rest.action.RestFieldCapabilitiesAction;
8081
import org.elasticsearch.rest.action.search.RestSearchAction;
8182
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
8283

@@ -85,10 +86,7 @@
8586
import java.net.URI;
8687
import java.net.URISyntaxException;
8788
import java.nio.charset.Charset;
88-
import java.util.Collections;
89-
import java.util.HashMap;
9089
import java.util.Locale;
91-
import java.util.Map;
9290
import java.util.StringJoiner;
9391

9492
final class RequestConverters {
@@ -600,6 +598,22 @@ static Request rollover(RolloverRequest rolloverRequest) throws IOException {
600598
return request;
601599
}
602600

601+
static Request getSettings(GetSettingsRequest getSettingsRequest) throws IOException {
602+
String[] indices = getSettingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getSettingsRequest.indices();
603+
String[] names = getSettingsRequest.names() == null ? Strings.EMPTY_ARRAY : getSettingsRequest.names();
604+
605+
String endpoint = endpoint(indices, "_settings", names);
606+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
607+
608+
Params params = new Params(request);
609+
params.withIndicesOptions(getSettingsRequest.indicesOptions());
610+
params.withLocal(getSettingsRequest.local());
611+
params.withIncludeDefaults(getSettingsRequest.includeDefaults());
612+
params.withMasterTimeout(getSettingsRequest.masterNodeTimeout());
613+
614+
return request;
615+
}
616+
603617
static Request indicesExist(GetIndexRequest getIndexRequest) {
604618
// this can be called with no indices as argument by transport client, not via REST though
605619
if (getIndexRequest.indices() == null || getIndexRequest.indices().length == 0) {
@@ -630,6 +644,21 @@ static Request indexPutSettings(UpdateSettingsRequest updateSettingsRequest) thr
630644
return request;
631645
}
632646

647+
static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) throws IOException {
648+
String endpoint = new EndpointBuilder().addPathPartAsIs("_template").addPathPart(putIndexTemplateRequest.name()).build();
649+
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
650+
Params params = new Params(request);
651+
params.withMasterTimeout(putIndexTemplateRequest.masterNodeTimeout());
652+
if (putIndexTemplateRequest.create()) {
653+
params.putParam("create", Boolean.TRUE.toString());
654+
}
655+
if (Strings.hasText(putIndexTemplateRequest.cause())) {
656+
params.putParam("cause", putIndexTemplateRequest.cause());
657+
}
658+
request.setEntity(createEntity(putIndexTemplateRequest, REQUEST_BODY_CONTENT_TYPE));
659+
return request;
660+
}
661+
633662
private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException {
634663
BytesRef source = XContentHelper.toXContent(toXContent, xContentType, false).toBytesRef();
635664
return new ByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType));

client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java

+170
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,19 @@
5151
import org.elasticsearch.action.admin.indices.rollover.RolloverResponse;
5252
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
5353
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse;
54+
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
55+
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
5456
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
5557
import org.elasticsearch.action.admin.indices.shrink.ResizeResponse;
5658
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
59+
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
60+
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
5761
import org.elasticsearch.action.index.IndexRequest;
5862
import org.elasticsearch.action.support.IndicesOptions;
5963
import org.elasticsearch.action.support.WriteRequest;
6064
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
6165
import org.elasticsearch.cluster.metadata.IndexMetaData;
66+
import org.elasticsearch.common.ValidationException;
6267
import org.elasticsearch.common.settings.Setting;
6368
import org.elasticsearch.common.settings.Settings;
6469
import org.elasticsearch.common.unit.ByteSizeUnit;
@@ -71,11 +76,19 @@
7176
import org.elasticsearch.rest.RestStatus;
7277

7378
import java.io.IOException;
79+
import java.util.Arrays;
80+
import java.util.Collections;
7481
import java.util.Map;
7582

7683
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
84+
import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractRawValues;
85+
import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue;
7786
import static org.hamcrest.CoreMatchers.hasItem;
87+
import static org.hamcrest.Matchers.contains;
88+
import static org.hamcrest.Matchers.containsString;
7889
import static org.hamcrest.Matchers.equalTo;
90+
import static org.hamcrest.Matchers.hasEntry;
91+
import static org.hamcrest.Matchers.hasSize;
7992
import static org.hamcrest.Matchers.not;
8093
import static org.hamcrest.Matchers.startsWith;
8194

@@ -189,6 +202,108 @@ public void testCreateIndex() throws IOException {
189202
}
190203
}
191204

205+
public void testGetSettings() throws IOException {
206+
String indexName = "get_settings_index";
207+
Settings basicSettings = Settings.builder()
208+
.put("number_of_shards", 1)
209+
.put("number_of_replicas", 0)
210+
.build();
211+
createIndex(indexName, basicSettings);
212+
213+
GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices(indexName);
214+
GetSettingsResponse getSettingsResponse = execute(getSettingsRequest, highLevelClient().indices()::getSettings,
215+
highLevelClient().indices()::getSettingsAsync);
216+
217+
assertNull(getSettingsResponse.getSetting(indexName, "index.refresh_interval"));
218+
assertEquals("1", getSettingsResponse.getSetting(indexName, "index.number_of_shards"));
219+
220+
updateIndexSettings(indexName, Settings.builder().put("refresh_interval", "30s"));
221+
222+
GetSettingsResponse updatedResponse = execute(getSettingsRequest, highLevelClient().indices()::getSettings,
223+
highLevelClient().indices()::getSettingsAsync);
224+
assertEquals("30s", updatedResponse.getSetting(indexName, "index.refresh_interval"));
225+
}
226+
227+
public void testGetSettingsNonExistentIndex() throws IOException {
228+
String nonExistentIndex = "index_that_doesnt_exist";
229+
assertFalse(indexExists(nonExistentIndex));
230+
231+
GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices(nonExistentIndex);
232+
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
233+
() -> execute(getSettingsRequest, highLevelClient().indices()::getSettings, highLevelClient().indices()::getSettingsAsync));
234+
assertEquals(RestStatus.NOT_FOUND, exception.status());
235+
}
236+
237+
public void testGetSettingsFromMultipleIndices() throws IOException {
238+
String indexName1 = "get_multiple_settings_one";
239+
createIndex(indexName1, Settings.builder().put("number_of_shards", 2).build());
240+
241+
String indexName2 = "get_multiple_settings_two";
242+
createIndex(indexName2, Settings.builder().put("number_of_shards", 3).build());
243+
244+
GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices("get_multiple_settings*");
245+
GetSettingsResponse getSettingsResponse = execute(getSettingsRequest, highLevelClient().indices()::getSettings,
246+
highLevelClient().indices()::getSettingsAsync);
247+
248+
assertEquals("2", getSettingsResponse.getSetting(indexName1, "index.number_of_shards"));
249+
assertEquals("3", getSettingsResponse.getSetting(indexName2, "index.number_of_shards"));
250+
}
251+
252+
public void testGetSettingsFiltered() throws IOException {
253+
String indexName = "get_settings_index";
254+
Settings basicSettings = Settings.builder()
255+
.put("number_of_shards", 1)
256+
.put("number_of_replicas", 0)
257+
.build();
258+
createIndex(indexName, basicSettings);
259+
260+
GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices(indexName).names("index.number_of_shards");
261+
GetSettingsResponse getSettingsResponse = execute(getSettingsRequest, highLevelClient().indices()::getSettings,
262+
highLevelClient().indices()::getSettingsAsync);
263+
264+
assertNull(getSettingsResponse.getSetting(indexName, "index.number_of_replicas"));
265+
assertEquals("1", getSettingsResponse.getSetting(indexName, "index.number_of_shards"));
266+
assertEquals(1, getSettingsResponse.getIndexToSettings().get("get_settings_index").size());
267+
}
268+
269+
public void testGetSettingsWithDefaults() throws IOException {
270+
String indexName = "get_settings_index";
271+
Settings basicSettings = Settings.builder()
272+
.put("number_of_shards", 1)
273+
.put("number_of_replicas", 0)
274+
.build();
275+
createIndex(indexName, basicSettings);
276+
277+
GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices(indexName).includeDefaults(true);
278+
GetSettingsResponse getSettingsResponse = execute(getSettingsRequest, highLevelClient().indices()::getSettings,
279+
highLevelClient().indices()::getSettingsAsync);
280+
281+
assertNotNull(getSettingsResponse.getSetting(indexName, "index.refresh_interval"));
282+
assertEquals(IndexSettings.DEFAULT_REFRESH_INTERVAL,
283+
getSettingsResponse.getIndexToDefaultSettings().get("get_settings_index").getAsTime("index.refresh_interval", null));
284+
assertEquals("1", getSettingsResponse.getSetting(indexName, "index.number_of_shards"));
285+
}
286+
287+
public void testGetSettingsWithDefaultsFiltered() throws IOException {
288+
String indexName = "get_settings_index";
289+
Settings basicSettings = Settings.builder()
290+
.put("number_of_shards", 1)
291+
.put("number_of_replicas", 0)
292+
.build();
293+
createIndex(indexName, basicSettings);
294+
295+
GetSettingsRequest getSettingsRequest = new GetSettingsRequest()
296+
.indices(indexName)
297+
.names("index.refresh_interval")
298+
.includeDefaults(true);
299+
GetSettingsResponse getSettingsResponse = execute(getSettingsRequest, highLevelClient().indices()::getSettings,
300+
highLevelClient().indices()::getSettingsAsync);
301+
302+
assertNull(getSettingsResponse.getSetting(indexName, "index.number_of_replicas"));
303+
assertNull(getSettingsResponse.getSetting(indexName, "index.number_of_shards"));
304+
assertEquals(0, getSettingsResponse.getIndexToSettings().get("get_settings_index").size());
305+
assertEquals(1, getSettingsResponse.getIndexToDefaultSettings().get("get_settings_index").size());
306+
}
192307
public void testPutMapping() throws IOException {
193308
{
194309
// Add mappings to index
@@ -708,4 +823,59 @@ public void testIndexPutSettingNonExistent() throws IOException {
708823
+ "or check the breaking changes documentation for removed settings]"));
709824
}
710825

826+
@SuppressWarnings("unchecked")
827+
public void testPutTemplate() throws Exception {
828+
PutIndexTemplateRequest putTemplateRequest = new PutIndexTemplateRequest()
829+
.name("my-template")
830+
.patterns(Arrays.asList("pattern-1", "name-*"))
831+
.order(10)
832+
.create(randomBoolean())
833+
.settings(Settings.builder().put("number_of_shards", "3").put("number_of_replicas", "0"))
834+
.mapping("doc", "host_name", "type=keyword", "description", "type=text")
835+
.alias(new Alias("alias-1").indexRouting("abc")).alias(new Alias("{index}-write").searchRouting("xyz"));
836+
837+
PutIndexTemplateResponse putTemplateResponse = execute(putTemplateRequest,
838+
highLevelClient().indices()::putTemplate, highLevelClient().indices()::putTemplateAsync);
839+
assertThat(putTemplateResponse.isAcknowledged(), equalTo(true));
840+
841+
Map<String, Object> templates = getAsMap("/_template/my-template");
842+
assertThat(templates.keySet(), hasSize(1));
843+
assertThat(extractValue("my-template.order", templates), equalTo(10));
844+
assertThat(extractRawValues("my-template.index_patterns", templates), contains("pattern-1", "name-*"));
845+
assertThat(extractValue("my-template.settings.index.number_of_shards", templates), equalTo("3"));
846+
assertThat(extractValue("my-template.settings.index.number_of_replicas", templates), equalTo("0"));
847+
assertThat(extractValue("my-template.mappings.doc.properties.host_name.type", templates), equalTo("keyword"));
848+
assertThat(extractValue("my-template.mappings.doc.properties.description.type", templates), equalTo("text"));
849+
assertThat((Map<String, String>) extractValue("my-template.aliases.alias-1", templates), hasEntry("index_routing", "abc"));
850+
assertThat((Map<String, String>) extractValue("my-template.aliases.{index}-write", templates), hasEntry("search_routing", "xyz"));
851+
}
852+
853+
public void testPutTemplateBadRequests() throws Exception {
854+
RestHighLevelClient client = highLevelClient();
855+
856+
// Failed to validate because index patterns are missing
857+
PutIndexTemplateRequest withoutPattern = new PutIndexTemplateRequest("t1");
858+
ValidationException withoutPatternError = expectThrows(ValidationException.class,
859+
() -> execute(withoutPattern, client.indices()::putTemplate, client.indices()::putTemplateAsync));
860+
assertThat(withoutPatternError.validationErrors(), contains("index patterns are missing"));
861+
862+
// Create-only specified but an template exists already
863+
PutIndexTemplateRequest goodTemplate = new PutIndexTemplateRequest("t2").patterns(Arrays.asList("qa-*", "prod-*"));
864+
assertTrue(execute(goodTemplate, client.indices()::putTemplate, client.indices()::putTemplateAsync).isAcknowledged());
865+
goodTemplate.create(true);
866+
ElasticsearchException alreadyExistsError = expectThrows(ElasticsearchException.class,
867+
() -> execute(goodTemplate, client.indices()::putTemplate, client.indices()::putTemplateAsync));
868+
assertThat(alreadyExistsError.getDetailedMessage(),
869+
containsString("[type=illegal_argument_exception, reason=index_template [t2] already exists]"));
870+
goodTemplate.create(false);
871+
assertTrue(execute(goodTemplate, client.indices()::putTemplate, client.indices()::putTemplateAsync).isAcknowledged());
872+
873+
// Rejected due to unknown settings
874+
PutIndexTemplateRequest unknownSettingTemplate = new PutIndexTemplateRequest("t3")
875+
.patterns(Collections.singletonList("any"))
876+
.settings(Settings.builder().put("this-setting-does-not-exist", 100));
877+
ElasticsearchStatusException unknownSettingError = expectThrows(ElasticsearchStatusException.class,
878+
() -> execute(unknownSettingTemplate, client.indices()::putTemplate, client.indices()::putTemplateAsync));
879+
assertThat(unknownSettingError.getDetailedMessage(), containsString("unknown setting [index.this-setting-does-not-exist]"));
880+
}
711881
}

0 commit comments

Comments
 (0)