Skip to content

Commit 07ecc03

Browse files
committed
Merge branch '6.x' into ccr-6.x
* 6.x: Avoid sending duplicate remote failed shard requests (#31313) Add get field mappings to High Level REST API Client Relates to #27205 [DOCS] Updates Watcher examples for code testing (#31152) [DOCS] Move monitoring to docs folder (#31477) [DOCS] Fixes SQL docs in nav [DOCS] Move sql to docs IndexShard should not return null stats - empty stats or AlreadyCloseException if it's closed is better Clarify that IP range data can be specified in CIDR notation. (#31374) Remove some cases in FieldTypeLookupTests that are no longer relevant. (#31381) In NumberFieldType equals and hashCode, make sure that NumberType is taken into account. (#31514) fix repository update with the same settings but different type Revert "AwaitsFix FullClusterRestartIT#testRecovery" Upgrade to Lucene 7.4.0. (#31529) Avoid deprecation warning when running the ML datafeed extractor. (#31463) Retry synced-flush in FullClusterRestartIT#testRecovery Allow multiple unicast host providers (#31509) [ML] Add ML filter update API (#31437) AwaitsFix FullClusterRestartIT#testRecovery Fix missing historyUUID in peer recovery when rolling upgrade 5.x to 6.3 (#31506) Remove QueryCachingPolicy#ALWAYS_CACHE (#31451) Rename createNewTranslog to fileBasedRecovery (#31508) [DOCS] Add code snippet testing in more ML APIs (#31339) [DOCS] Remove fixed file from build.gradle [DOCS] Creates field and document level security overview (#30937) Test: Skip assertion on windows [DOCS] Move migration APIs to docs (#31473) Add a known issue for upgrading from 5.x to 6.3.0 (#31501) Return transport addresses from UnicastHostsProvider (#31426) Add Delete Snapshot High Level REST API Reload secure settings for plugins (#31481) [DOCS] Fix JDBC Maven client group/artifact ID
2 parents faea9c4 + b66ce89 commit 07ecc03

File tree

286 files changed

+6723
-2395
lines changed

Some content is hidden

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

286 files changed

+6723
-2395
lines changed

buildSrc/version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
elasticsearch = 6.4.0
2-
lucene = 7.4.0-snapshot-518d303506
2+
lucene = 7.4.0
33

44
# optional dependencies
55
spatial4j = 0.7

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
3939
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
4040
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
41+
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
42+
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
4143
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
4244
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
4345
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
@@ -268,6 +270,35 @@ public void getMappingsAsync(GetMappingsRequest getMappingsRequest, RequestOptio
268270
GetMappingsResponse::fromXContent, listener, emptySet());
269271
}
270272

273+
/**
274+
* Retrieves the field mappings on an index or indices using the Get Field Mapping API.
275+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html">
276+
* Get Field Mapping API on elastic.co</a>
277+
* @param getFieldMappingsRequest the request
278+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
279+
* @return the response
280+
* @throws IOException in case there is a problem sending the request or parsing back the response
281+
*/
282+
public GetFieldMappingsResponse getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest,
283+
RequestOptions options) throws IOException {
284+
return restHighLevelClient.performRequestAndParseEntity(getFieldMappingsRequest, RequestConverters::getFieldMapping, options,
285+
GetFieldMappingsResponse::fromXContent, emptySet());
286+
}
287+
288+
/**
289+
* Asynchronously retrieves the field mappings on an index on indices using the Get Field Mapping API.
290+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html">
291+
* Get Field Mapping API on elastic.co</a>
292+
* @param getFieldMappingsRequest the request
293+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
294+
* @param listener the listener to be notified upon request completion
295+
*/
296+
public void getFieldMappingAsync(GetFieldMappingsRequest getFieldMappingsRequest, RequestOptions options,
297+
ActionListener<GetFieldMappingsResponse> listener) {
298+
restHighLevelClient.performRequestAsyncAndParseEntity(getFieldMappingsRequest, RequestConverters::getFieldMapping, options,
299+
GetFieldMappingsResponse::fromXContent, listener, emptySet());
300+
}
301+
271302
/**
272303
* Updates aliases using the Index Aliases API.
273304
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html">

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
4040
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
4141
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
42+
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
4243
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
4344
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
4445
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
@@ -49,6 +50,7 @@
4950
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
5051
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
5152
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
53+
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
5254
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
5355
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
5456
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
@@ -231,6 +233,25 @@ static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOExcep
231233
return request;
232234
}
233235

236+
static Request getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest) throws IOException {
237+
String[] indices = getFieldMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.indices();
238+
String[] types = getFieldMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.types();
239+
String[] fields = getFieldMappingsRequest.fields() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.fields();
240+
241+
String endpoint = new EndpointBuilder().addCommaSeparatedPathParts(indices)
242+
.addPathPartAsIs("_mapping").addCommaSeparatedPathParts(types)
243+
.addPathPartAsIs("field").addCommaSeparatedPathParts(fields)
244+
.build();
245+
246+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
247+
248+
Params parameters = new Params(request);
249+
parameters.withIndicesOptions(getFieldMappingsRequest.indicesOptions());
250+
parameters.withIncludeDefaults(getFieldMappingsRequest.includeDefaults());
251+
parameters.withLocal(getFieldMappingsRequest.local());
252+
return request;
253+
}
254+
234255
static Request refresh(RefreshRequest refreshRequest) {
235256
String[] indices = refreshRequest.indices() == null ? Strings.EMPTY_ARRAY : refreshRequest.indices();
236257
Request request = new Request(HttpPost.METHOD_NAME, endpoint(indices, "_refresh"));
@@ -855,6 +876,18 @@ static Request verifyRepository(VerifyRepositoryRequest verifyRepositoryRequest)
855876
return request;
856877
}
857878

879+
static Request deleteSnapshot(DeleteSnapshotRequest deleteSnapshotRequest) {
880+
String endpoint = new EndpointBuilder().addPathPartAsIs("_snapshot")
881+
.addPathPart(deleteSnapshotRequest.repository())
882+
.addPathPart(deleteSnapshotRequest.snapshot())
883+
.build();
884+
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
885+
886+
Params parameters = new Params(request);
887+
parameters.withMasterTimeout(deleteSnapshotRequest.masterNodeTimeout());
888+
return request;
889+
}
890+
858891
static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) throws IOException {
859892
String endpoint = new EndpointBuilder().addPathPartAsIs("_template").addPathPart(putIndexTemplateRequest.name()).build();
860893
Request request = new Request(HttpPut.METHOD_NAME, endpoint);

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse;
2929
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
3030
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse;
31+
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
32+
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse;
3133

3234
import java.io.IOException;
3335

@@ -161,4 +163,34 @@ public void verifyRepositoryAsync(VerifyRepositoryRequest verifyRepositoryReques
161163
restHighLevelClient.performRequestAsyncAndParseEntity(verifyRepositoryRequest, RequestConverters::verifyRepository, options,
162164
VerifyRepositoryResponse::fromXContent, listener, emptySet());
163165
}
166+
167+
/**
168+
* Deletes a snapshot.
169+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
170+
* API on elastic.co</a>
171+
*
172+
* @param deleteSnapshotRequest the request
173+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
174+
* @return the response
175+
* @throws IOException in case there is a problem sending the request or parsing back the response
176+
*/
177+
public DeleteSnapshotResponse delete(DeleteSnapshotRequest deleteSnapshotRequest, RequestOptions options) throws IOException {
178+
return restHighLevelClient.performRequestAndParseEntity(deleteSnapshotRequest, RequestConverters::deleteSnapshot, options,
179+
DeleteSnapshotResponse::fromXContent, emptySet());
180+
}
181+
182+
/**
183+
* Asynchronously deletes a snapshot.
184+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-snapshots.html"> Snapshot and Restore
185+
* API on elastic.co</a>
186+
*
187+
* @param deleteSnapshotRequest the request
188+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
189+
* @param listener the listener to be notified upon request completion
190+
*/
191+
public void deleteAsync(DeleteSnapshotRequest deleteSnapshotRequest, RequestOptions options,
192+
ActionListener<DeleteSnapshotResponse> listener) {
193+
restHighLevelClient.performRequestAsyncAndParseEntity(deleteSnapshotRequest, RequestConverters::deleteSnapshot, options,
194+
DeleteSnapshotResponse::fromXContent, listener, emptySet());
195+
}
164196
}

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
4444
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
4545
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
46+
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
47+
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
4648
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
4749
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
4850
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
@@ -75,6 +77,7 @@
7577
import org.elasticsearch.cluster.metadata.IndexMetaData;
7678
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
7779
import org.elasticsearch.common.ValidationException;
80+
import org.elasticsearch.common.bytes.BytesArray;
7881
import org.elasticsearch.common.settings.Setting;
7982
import org.elasticsearch.common.settings.Settings;
8083
import org.elasticsearch.common.unit.ByteSizeUnit;
@@ -388,6 +391,41 @@ public void testGetMapping() throws IOException {
388391
assertThat(mappings, equalTo(expected));
389392
}
390393

394+
public void testGetFieldMapping() throws IOException {
395+
String indexName = "test";
396+
createIndex(indexName, Settings.EMPTY);
397+
398+
PutMappingRequest putMappingRequest = new PutMappingRequest(indexName);
399+
putMappingRequest.type("_doc");
400+
XContentBuilder mappingBuilder = JsonXContent.contentBuilder();
401+
mappingBuilder.startObject().startObject("properties").startObject("field");
402+
mappingBuilder.field("type", "text");
403+
mappingBuilder.endObject().endObject().endObject();
404+
putMappingRequest.source(mappingBuilder);
405+
406+
PutMappingResponse putMappingResponse =
407+
execute(putMappingRequest, highLevelClient().indices()::putMapping, highLevelClient().indices()::putMappingAsync);
408+
assertTrue(putMappingResponse.isAcknowledged());
409+
410+
GetFieldMappingsRequest getFieldMappingsRequest = new GetFieldMappingsRequest()
411+
.indices(indexName)
412+
.types("_doc")
413+
.fields("field");
414+
415+
GetFieldMappingsResponse getFieldMappingsResponse =
416+
execute(getFieldMappingsRequest,
417+
highLevelClient().indices()::getFieldMapping,
418+
highLevelClient().indices()::getFieldMappingAsync);
419+
420+
final Map<String, GetFieldMappingsResponse.FieldMappingMetaData> fieldMappingMap =
421+
getFieldMappingsResponse.mappings().get(indexName).get("_doc");
422+
423+
final GetFieldMappingsResponse.FieldMappingMetaData metaData =
424+
new GetFieldMappingsResponse.FieldMappingMetaData("field",
425+
new BytesArray("{\"field\":{\"type\":\"text\"}}"));
426+
assertThat(fieldMappingMap, equalTo(Collections.singletonMap("field", metaData)));
427+
}
428+
391429
public void testDeleteIndex() throws IOException {
392430
{
393431
// Delete index if exists

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

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
3838
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
3939
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
40+
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
4041
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
4142
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
4243
import org.elasticsearch.action.admin.indices.alias.Alias;
@@ -51,6 +52,7 @@
5152
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
5253
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
5354
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
55+
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
5456
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
5557
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
5658
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
@@ -465,6 +467,61 @@ public void testGetMapping() throws IOException {
465467
assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod()));
466468
}
467469

470+
public void testGetFieldMapping() throws IOException {
471+
GetFieldMappingsRequest getFieldMappingsRequest = new GetFieldMappingsRequest();
472+
473+
String[] indices = Strings.EMPTY_ARRAY;
474+
if (randomBoolean()) {
475+
indices = randomIndicesNames(0, 5);
476+
getFieldMappingsRequest.indices(indices);
477+
} else if (randomBoolean()) {
478+
getFieldMappingsRequest.indices((String[]) null);
479+
}
480+
481+
String type = null;
482+
if (randomBoolean()) {
483+
type = randomAlphaOfLengthBetween(3, 10);
484+
getFieldMappingsRequest.types(type);
485+
} else if (randomBoolean()) {
486+
getFieldMappingsRequest.types((String[]) null);
487+
}
488+
489+
String[] fields = null;
490+
if (randomBoolean()) {
491+
fields = new String[randomIntBetween(1, 5)];
492+
for (int i = 0; i < fields.length; i++) {
493+
fields[i] = randomAlphaOfLengthBetween(3, 10);
494+
}
495+
getFieldMappingsRequest.fields(fields);
496+
} else if (randomBoolean()) {
497+
getFieldMappingsRequest.fields((String[]) null);
498+
}
499+
500+
Map<String, String> expectedParams = new HashMap<>();
501+
502+
setRandomIndicesOptions(getFieldMappingsRequest::indicesOptions, getFieldMappingsRequest::indicesOptions, expectedParams);
503+
setRandomLocal(getFieldMappingsRequest::local, expectedParams);
504+
505+
Request request = RequestConverters.getFieldMapping(getFieldMappingsRequest);
506+
StringJoiner endpoint = new StringJoiner("/", "/", "");
507+
String index = String.join(",", indices);
508+
if (Strings.hasLength(index)) {
509+
endpoint.add(index);
510+
}
511+
endpoint.add("_mapping");
512+
if (type != null) {
513+
endpoint.add(type);
514+
}
515+
endpoint.add("field");
516+
if (fields != null) {
517+
endpoint.add(String.join(",", fields));
518+
}
519+
assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
520+
521+
assertThat(expectedParams, equalTo(request.getParameters()));
522+
assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod()));
523+
}
524+
468525
public void testDeleteIndex() {
469526
String[] indices = randomIndicesNames(0, 5);
470527
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indices);
@@ -1890,6 +1947,25 @@ public void testVerifyRepository() {
18901947
assertThat(expectedParams, equalTo(request.getParameters()));
18911948
}
18921949

1950+
public void testDeleteSnapshot() {
1951+
Map<String, String> expectedParams = new HashMap<>();
1952+
String repository = randomIndicesNames(1, 1)[0];
1953+
String snapshot = "snapshot-" + randomAlphaOfLengthBetween(2, 5).toLowerCase(Locale.ROOT);
1954+
1955+
String endpoint = String.format(Locale.ROOT, "/_snapshot/%s/%s", repository, snapshot);
1956+
1957+
DeleteSnapshotRequest deleteSnapshotRequest = new DeleteSnapshotRequest();
1958+
deleteSnapshotRequest.repository(repository);
1959+
deleteSnapshotRequest.snapshot(snapshot);
1960+
setRandomMasterTimeout(deleteSnapshotRequest, expectedParams);
1961+
1962+
Request request = RequestConverters.deleteSnapshot(deleteSnapshotRequest);
1963+
assertThat(endpoint, equalTo(request.getEndpoint()));
1964+
assertThat(HttpDelete.METHOD_NAME, equalTo(request.getMethod()));
1965+
assertThat(expectedParams, equalTo(request.getParameters()));
1966+
assertNull(request.getEntity());
1967+
}
1968+
18931969
public void testPutTemplateRequest() throws Exception {
18941970
Map<String, String> names = new HashMap<>();
18951971
names.put("log", "log");
@@ -2252,16 +2328,20 @@ private static void setRandomHumanReadable(GetIndexRequest request, Map<String,
22522328
}
22532329
}
22542330

2255-
private static void setRandomLocal(MasterNodeReadRequest<?> request, Map<String, String> expectedParams) {
2331+
private static void setRandomLocal(Consumer<Boolean> setter, Map<String, String> expectedParams) {
22562332
if (randomBoolean()) {
22572333
boolean local = randomBoolean();
2258-
request.local(local);
2334+
setter.accept(local);
22592335
if (local) {
22602336
expectedParams.put("local", String.valueOf(local));
22612337
}
22622338
}
22632339
}
22642340

2341+
private static void setRandomLocal(MasterNodeReadRequest<?> request, Map<String, String> expectedParams) {
2342+
setRandomLocal(request::local, expectedParams);
2343+
}
2344+
22652345
private static void setRandomTimeout(Consumer<String> setter, TimeValue defaultTimeout, Map<String, String> expectedParams) {
22662346
if (randomBoolean()) {
22672347
String timeout = randomTimeValue();

0 commit comments

Comments
 (0)