Skip to content

Commit 6dd3434

Browse files
committed
Merge branch 'master' into ccr
* master: REST high-level client: add get index API (#31703) SQL: Allow long literals (#31777) SQL: Fix incorrect message for aliases (#31792) Test: Do not remove xpack templates when cleaning (#31642) Reduce more raw types warnings (#31780) Add unreleased version 6.3.2 Scripting: Remove support for deprecated StoredScript contexts (#31394) [ML][TEST] Use java 11 valid time format in DataDescriptionTests (#31817) [ML] Don't treat stale FAILED jobs as OPENING in job allocation (#31800) [ML] Fix calendar and filter updates from non-master nodes (#31804) Fix license header generation on Windows (#31790) mark RollupIT.testTwoJobsStartStopDeleteOne as AwaitsFix mark SearchAsyncActionTests.testFanOutAndCollect as AwaitsFix Correct exclusion of test on JDK 11 Fix doclint jdk 11 Add JDK11 support and enable in CI (#31644) Watcher: Fix check for currently executed watches (#31137) Watcher: Ensure correct method is used to read secure settings (#31753) SQL: Update CLI logo
2 parents f736205 + 09e8ac8 commit 6dd3434

File tree

134 files changed

+1487
-786
lines changed

Some content is hidden

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

134 files changed

+1487
-786
lines changed

.ci/matrix-build-javas.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77

88
ES_BUILD_JAVA:
99
- java10
10+
- java11

.ci/matrix-runtime-javas.yml

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
ES_RUNTIME_JAVA:
99
- java8
1010
- java10
11+
- java11

build.gradle

+9-2
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,19 @@ allprojects {
445445
}
446446

447447
File licenseHeaderFile;
448-
if (eclipse.project.name.startsWith(':x-pack')) {
448+
String prefix = ':x-pack';
449+
450+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
451+
prefix = prefix.replace(':', '_')
452+
}
453+
if (eclipse.project.name.startsWith(prefix)) {
449454
licenseHeaderFile = new File(project.rootDir, 'buildSrc/src/main/resources/license-headers/elastic-license-header.txt')
450455
} else {
451456
licenseHeaderFile = new File(project.rootDir, 'buildSrc/src/main/resources/license-headers/oss-license-header.txt')
452457
}
453-
String licenseHeader = licenseHeaderFile.getText('UTF-8').replace('\n', '\\\\n')
458+
459+
String lineSeparator = Os.isFamily(Os.FAMILY_WINDOWS) ? '\\\\r\\\\n' : '\\\\n'
460+
String licenseHeader = licenseHeaderFile.getText('UTF-8').replace(System.lineSeparator(), lineSeparator)
454461
task copyEclipseSettings(type: Copy) {
455462
// TODO: "package this up" for external builds
456463
from new File(project.rootDir, 'buildSrc/src/main/resources/eclipse.settings')

buildSrc/src/main/resources/forbidden/jdk-signatures.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ java.lang.Thread#getAllStackTraces()
8888

8989
@defaultMessage Stopping threads explicitly leads to inconsistent states. Use interrupt() instead.
9090
java.lang.Thread#stop()
91-
java.lang.Thread#stop(java.lang.Throwable)
91+
# uncomment when https://github.com/elastic/elasticsearch/issues/31715 is fixed
92+
# java.lang.Thread#stop(java.lang.Throwable)
9293

9394
@defaultMessage Please do not terminate the application
9495
java.lang.System#exit(int)

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

+29
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
4040
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
4141
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
42+
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
4243
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
4344
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
4445
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
@@ -437,6 +438,34 @@ public void getSettingsAsync(GetSettingsRequest getSettingsRequest, RequestOptio
437438
GetSettingsResponse::fromXContent, listener, emptySet());
438439
}
439440

441+
/**
442+
* Retrieve information about one or more indexes
443+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html">
444+
* Indices Get Index API on elastic.co</a>
445+
* @param getIndexRequest the request
446+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
447+
* @return the response
448+
* @throws IOException in case there is a problem sending the request or parsing back the response
449+
*/
450+
public GetIndexResponse get(GetIndexRequest getIndexRequest, RequestOptions options) throws IOException {
451+
return restHighLevelClient.performRequestAndParseEntity(getIndexRequest, RequestConverters::getIndex, options,
452+
GetIndexResponse::fromXContent, emptySet());
453+
}
454+
455+
/**
456+
* Retrieve information about one or more indexes
457+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html">
458+
* Indices Get Index API on elastic.co</a>
459+
* @param getIndexRequest the request
460+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
461+
* @param listener the listener to be notified upon request completion
462+
*/
463+
public void getAsync(GetIndexRequest getIndexRequest, RequestOptions options,
464+
ActionListener<GetIndexResponse> listener) {
465+
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexRequest, RequestConverters::getIndex, options,
466+
GetIndexResponse::fromXContent, listener, emptySet());
467+
}
468+
440469
/**
441470
* Force merge one or more indices using the Force Merge API.
442471
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html">

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

+16
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,22 @@ static Request getSettings(GetSettingsRequest getSettingsRequest) {
834834
return request;
835835
}
836836

837+
static Request getIndex(GetIndexRequest getIndexRequest) {
838+
String[] indices = getIndexRequest.indices() == null ? Strings.EMPTY_ARRAY : getIndexRequest.indices();
839+
840+
String endpoint = endpoint(indices);
841+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
842+
843+
Params params = new Params(request);
844+
params.withIndicesOptions(getIndexRequest.indicesOptions());
845+
params.withLocal(getIndexRequest.local());
846+
params.withIncludeDefaults(getIndexRequest.includeDefaults());
847+
params.withHuman(getIndexRequest.humanReadable());
848+
params.withMasterTimeout(getIndexRequest.masterNodeTimeout());
849+
850+
return request;
851+
}
852+
837853
static Request indicesExist(GetIndexRequest getIndexRequest) {
838854
// this can be called with no indices as argument by transport client, not via REST though
839855
if (getIndexRequest.indices() == null || getIndexRequest.indices().length == 0) {

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

+72
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
4646
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
4747
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
48+
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
4849
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
4950
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
5051
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
@@ -99,6 +100,7 @@
99100
import java.util.Map;
100101

101102
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
103+
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
102104
import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractRawValues;
103105
import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue;
104106
import static org.hamcrest.CoreMatchers.hasItem;
@@ -112,6 +114,7 @@
112114
import static org.hamcrest.Matchers.notNullValue;
113115
import static org.hamcrest.Matchers.nullValue;
114116
import static org.hamcrest.Matchers.startsWith;
117+
import static org.hamcrest.core.IsInstanceOf.instanceOf;
115118

116119
public class IndicesClientIT extends ESRestHighLevelClientTestCase {
117120

@@ -326,6 +329,75 @@ public void testGetSettingsWithDefaultsFiltered() throws IOException {
326329
assertEquals(1, getSettingsResponse.getIndexToDefaultSettings().get("get_settings_index").size());
327330
}
328331

332+
@SuppressWarnings("unchecked")
333+
public void testGetIndex() throws IOException {
334+
String indexName = "get_index_test";
335+
Settings basicSettings = Settings.builder()
336+
.put(SETTING_NUMBER_OF_SHARDS, 1)
337+
.put(SETTING_NUMBER_OF_REPLICAS, 0)
338+
.build();
339+
String mappings = "\"type-1\":{\"properties\":{\"field-1\":{\"type\":\"integer\"}}}";
340+
createIndex(indexName, basicSettings, mappings);
341+
342+
GetIndexRequest getIndexRequest = new GetIndexRequest()
343+
.indices(indexName).includeDefaults(false);
344+
GetIndexResponse getIndexResponse =
345+
execute(getIndexRequest, highLevelClient().indices()::get, highLevelClient().indices()::getAsync);
346+
347+
// default settings should be null
348+
assertNull(getIndexResponse.getSetting(indexName, "index.refresh_interval"));
349+
assertEquals("1", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_SHARDS));
350+
assertEquals("0", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_REPLICAS));
351+
assertNotNull(getIndexResponse.getMappings().get(indexName));
352+
assertNotNull(getIndexResponse.getMappings().get(indexName).get("type-1"));
353+
Object o = getIndexResponse.getMappings().get(indexName).get("type-1").getSourceAsMap().get("properties");
354+
assertThat(o, instanceOf(Map.class));
355+
//noinspection unchecked
356+
assertThat(((Map<String, Object>) o).get("field-1"), instanceOf(Map.class));
357+
//noinspection unchecked
358+
Map<String, Object> fieldMapping = (Map<String, Object>) ((Map<String, Object>) o).get("field-1");
359+
assertEquals("integer", fieldMapping.get("type"));
360+
}
361+
362+
@SuppressWarnings("unchecked")
363+
public void testGetIndexWithDefaults() throws IOException {
364+
String indexName = "get_index_test";
365+
Settings basicSettings = Settings.builder()
366+
.put(SETTING_NUMBER_OF_SHARDS, 1)
367+
.put(SETTING_NUMBER_OF_REPLICAS, 0)
368+
.build();
369+
String mappings = "\"type-1\":{\"properties\":{\"field-1\":{\"type\":\"integer\"}}}";
370+
createIndex(indexName, basicSettings, mappings);
371+
372+
GetIndexRequest getIndexRequest = new GetIndexRequest()
373+
.indices(indexName).includeDefaults(true);
374+
GetIndexResponse getIndexResponse =
375+
execute(getIndexRequest, highLevelClient().indices()::get, highLevelClient().indices()::getAsync);
376+
377+
assertNotNull(getIndexResponse.getSetting(indexName, "index.refresh_interval"));
378+
assertEquals(IndexSettings.DEFAULT_REFRESH_INTERVAL,
379+
getIndexResponse.defaultSettings().get(indexName).getAsTime("index.refresh_interval", null));
380+
assertEquals("1", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_SHARDS));
381+
assertEquals("0", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_REPLICAS));
382+
assertNotNull(getIndexResponse.getMappings().get(indexName));
383+
assertNotNull(getIndexResponse.getMappings().get(indexName).get("type-1"));
384+
Object o = getIndexResponse.getMappings().get(indexName).get("type-1").getSourceAsMap().get("properties");
385+
assertThat(o, instanceOf(Map.class));
386+
assertThat(((Map<String, Object>) o).get("field-1"), instanceOf(Map.class));
387+
Map<String, Object> fieldMapping = (Map<String, Object>) ((Map<String, Object>) o).get("field-1");
388+
assertEquals("integer", fieldMapping.get("type"));
389+
}
390+
391+
public void testGetIndexNonExistentIndex() throws IOException {
392+
String nonExistentIndex = "index_that_doesnt_exist";
393+
assertFalse(indexExists(nonExistentIndex));
394+
395+
GetIndexRequest getIndexRequest = new GetIndexRequest().indices(nonExistentIndex);
396+
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
397+
() -> execute(getIndexRequest, highLevelClient().indices()::get, highLevelClient().indices()::getAsync));
398+
assertEquals(RestStatus.NOT_FOUND, exception.status());
399+
}
400+
329401
public void testPutMapping() throws IOException {
330402
// Add mappings to index
331403
String indexName = "mapping_index";

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

+33
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,39 @@ public void testGetSettings() throws IOException {
584584
assertThat(request.getEntity(), nullValue());
585585
}
586586

587+
public void testGetIndex() throws IOException {
588+
String[] indicesUnderTest = randomBoolean() ? null : randomIndicesNames(0, 5);
589+
590+
GetIndexRequest getIndexRequest = new GetIndexRequest().indices(indicesUnderTest);
591+
592+
Map<String, String> expectedParams = new HashMap<>();
593+
setRandomMasterTimeout(getIndexRequest, expectedParams);
594+
setRandomIndicesOptions(getIndexRequest::indicesOptions, getIndexRequest::indicesOptions, expectedParams);
595+
setRandomLocal(getIndexRequest, expectedParams);
596+
setRandomHumanReadable(getIndexRequest, expectedParams);
597+
598+
if (randomBoolean()) {
599+
// the request object will not have include_defaults present unless it is set to
600+
// true
601+
getIndexRequest.includeDefaults(randomBoolean());
602+
if (getIndexRequest.includeDefaults()) {
603+
expectedParams.put("include_defaults", Boolean.toString(true));
604+
}
605+
}
606+
607+
StringJoiner endpoint = new StringJoiner("/", "/", "");
608+
if (indicesUnderTest != null && indicesUnderTest.length > 0) {
609+
endpoint.add(String.join(",", indicesUnderTest));
610+
}
611+
612+
Request request = RequestConverters.getIndex(getIndexRequest);
613+
614+
assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
615+
assertThat(request.getParameters(), equalTo(expectedParams));
616+
assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
617+
assertThat(request.getEntity(), nullValue());
618+
}
619+
587620
public void testDeleteIndexEmptyIndices() {
588621
String[] indices = randomBoolean() ? null : Strings.EMPTY_ARRAY;
589622
ActionRequestValidationException validationException = new DeleteIndexRequest(indices).validate();

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

+78
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
4545
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
4646
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
47+
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
4748
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
4849
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
4950
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
@@ -89,12 +90,14 @@
8990
import org.elasticsearch.common.xcontent.XContentBuilder;
9091
import org.elasticsearch.common.xcontent.XContentFactory;
9192
import org.elasticsearch.common.xcontent.XContentType;
93+
import org.elasticsearch.index.IndexSettings;
9294
import org.elasticsearch.index.query.QueryBuilder;
9395
import org.elasticsearch.index.query.QueryBuilders;
9496
import org.elasticsearch.rest.RestStatus;
9597

9698
import java.io.IOException;
9799
import java.util.Arrays;
100+
import java.util.Collections;
98101
import java.util.HashMap;
99102
import java.util.List;
100103
import java.util.Map;
@@ -1235,6 +1238,81 @@ public void onFailure(Exception e) {
12351238
assertTrue(latch.await(30L, TimeUnit.SECONDS));
12361239
}
12371240

1241+
public void testGetIndex() throws Exception {
1242+
RestHighLevelClient client = highLevelClient();
1243+
1244+
{
1245+
Settings settings = Settings.builder().put("number_of_shards", 3).build();
1246+
String mappings = "{\"properties\":{\"field-1\":{\"type\":\"integer\"}}}";
1247+
CreateIndexResponse createIndexResponse = client.indices().create(
1248+
new CreateIndexRequest("index", settings).mapping("doc", mappings, XContentType.JSON),
1249+
RequestOptions.DEFAULT);
1250+
assertTrue(createIndexResponse.isAcknowledged());
1251+
}
1252+
1253+
// tag::get-index-request
1254+
GetIndexRequest request = new GetIndexRequest().indices("index"); // <1>
1255+
// end::get-index-request
1256+
1257+
// tag::get-index-request-indicesOptions
1258+
request.indicesOptions(IndicesOptions.lenientExpandOpen()); // <1>
1259+
// end::get-index-request-indicesOptions
1260+
1261+
// tag::get-index-request-includeDefaults
1262+
request.includeDefaults(true); // <1>
1263+
// end::get-index-request-includeDefaults
1264+
1265+
// tag::get-index-execute
1266+
GetIndexResponse getIndexResponse = client.indices().get(request, RequestOptions.DEFAULT);
1267+
// end::get-index-execute
1268+
1269+
// tag::get-index-response
1270+
ImmutableOpenMap<String, MappingMetaData> indexMappings = getIndexResponse.getMappings().get("index"); // <1>
1271+
Map<String, Object> indexTypeMappings = indexMappings.get("doc").getSourceAsMap(); // <2>
1272+
List<AliasMetaData> indexAliases = getIndexResponse.getAliases().get("index"); // <3>
1273+
String numberOfShardsString = getIndexResponse.getSetting("index", "index.number_of_shards"); // <4>
1274+
Settings indexSettings = getIndexResponse.getSettings().get("index"); // <5>
1275+
Integer numberOfShards = indexSettings.getAsInt("index.number_of_shards", null); // <6>
1276+
TimeValue time = getIndexResponse.defaultSettings().get("index")
1277+
.getAsTime("index.refresh_interval", null); // <7>
1278+
// end::get-index-response
1279+
1280+
assertEquals(
1281+
Collections.singletonMap("properties",
1282+
Collections.singletonMap("field-1", Collections.singletonMap("type", "integer"))),
1283+
indexTypeMappings
1284+
);
1285+
assertTrue(indexAliases.isEmpty());
1286+
assertEquals(IndexSettings.DEFAULT_REFRESH_INTERVAL, time);
1287+
assertEquals("3", numberOfShardsString);
1288+
assertEquals(Integer.valueOf(3), numberOfShards);
1289+
1290+
// tag::get-index-execute-listener
1291+
ActionListener<GetIndexResponse> listener =
1292+
new ActionListener<GetIndexResponse>() {
1293+
@Override
1294+
public void onResponse(GetIndexResponse getIndexResponse) {
1295+
// <1>
1296+
}
1297+
1298+
@Override
1299+
public void onFailure(Exception e) {
1300+
// <2>
1301+
}
1302+
};
1303+
// end::get-index-execute-listener
1304+
1305+
// Replace the empty listener by a blocking listener in test
1306+
final CountDownLatch latch = new CountDownLatch(1);
1307+
listener = new LatchedActionListener<>(listener, latch);
1308+
1309+
// tag::get-index-execute-async
1310+
client.indices().getAsync(request, RequestOptions.DEFAULT, listener); // <1>
1311+
// end::get-index-execute-async
1312+
1313+
assertTrue(latch.await(30L, TimeUnit.SECONDS));
1314+
}
1315+
12381316
public void testForceMergeIndex() throws Exception {
12391317
RestHighLevelClient client = highLevelClient();
12401318

0 commit comments

Comments
 (0)