Skip to content

Commit 5074683

Browse files
committed
Merge branch 'master' into security_authz_engine
2 parents 74f2e99 + 3c9f703 commit 5074683

File tree

293 files changed

+7163
-1599
lines changed

Some content is hidden

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

293 files changed

+7163
-1599
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantTestPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class VagrantTestPlugin implements Plugin<Project> {
630630
void afterExecute(Task task, TaskState state) {
631631
final String gradlew = Os.isFamily(Os.FAMILY_WINDOWS) ? "gradlew" : "./gradlew"
632632
if (state.failure != null) {
633-
println "REPRODUCE WITH: ${gradlew} ${reproTaskPath} -Dtests.seed=${project.testSeed} "
633+
println "REPRODUCE WITH: ${gradlew} \"${reproTaskPath}\" -Dtests.seed=${project.testSeed} "
634634
}
635635
}
636636
}

buildSrc/src/test/java/org/elasticsearch/gradle/BuildExamplePluginsIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
2424
import org.gradle.testkit.runner.GradleRunner;
2525
import org.junit.BeforeClass;
26+
import org.junit.Ignore;
2627
import org.junit.Rule;
2728
import org.junit.rules.TemporaryFolder;
2829

@@ -38,6 +39,7 @@
3839
import java.util.Objects;
3940
import java.util.stream.Collectors;
4041

42+
@Ignore // Awaiting a fix in https://github.com/elastic/elasticsearch/issues/37889.
4143
public class BuildExamplePluginsIT extends GradleIntegrationTestCase {
4244

4345
private static final List<File> EXAMPLE_PLUGINS = Collections.unmodifiableList(

buildSrc/src/test/java/org/elasticsearch/gradle/testclusters/TestClustersPluginIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
import org.elasticsearch.gradle.test.GradleIntegrationTestCase;
2222
import org.gradle.testkit.runner.BuildResult;
2323
import org.gradle.testkit.runner.GradleRunner;
24+
import org.junit.Ignore;
2425

2526
import java.util.Arrays;
2627

28+
@Ignore // Awaiting a fix in https://github.com/elastic/elasticsearch/issues/37889.
2729
public class TestClustersPluginIT extends GradleIntegrationTestCase {
2830

2931
public void testListClusters() {

client/rest-high-level/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ integTestCluster {
107107
// Truststore settings are not used since TLS is not enabled. Included for testing the get certificates API
108108
setting 'xpack.security.http.ssl.certificate_authorities', 'testnode.crt'
109109
setting 'xpack.security.transport.ssl.truststore.path', 'testnode.jks'
110+
setting 'indices.lifecycle.poll_interval', '1000ms'
110111
keystoreSetting 'xpack.security.transport.ssl.truststore.secure_password', 'testnode'
111112
setupCommand 'setupDummyUser',
112113
'bin/elasticsearch-users',

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

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
3838
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
3939
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
40-
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
41-
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
4240
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
4341
import org.elasticsearch.action.admin.indices.open.OpenIndexResponse;
4442
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
@@ -61,6 +59,8 @@
6159
import org.elasticsearch.client.indices.CreateIndexResponse;
6260
import org.elasticsearch.client.indices.FreezeIndexRequest;
6361
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
62+
import org.elasticsearch.client.indices.GetMappingsRequest;
63+
import org.elasticsearch.client.indices.GetMappingsResponse;
6464
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
6565
import org.elasticsearch.client.indices.PutMappingRequest;
6666
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
@@ -261,8 +261,11 @@ public void putMappingAsync(org.elasticsearch.action.admin.indices.mapping.put.P
261261
* @throws IOException in case there is a problem sending the request or parsing back the response
262262
*/
263263
public GetMappingsResponse getMapping(GetMappingsRequest getMappingsRequest, RequestOptions options) throws IOException {
264-
return restHighLevelClient.performRequestAndParseEntity(getMappingsRequest, IndicesRequestConverters::getMappings, options,
265-
GetMappingsResponse::fromXContent, emptySet());
264+
return restHighLevelClient.performRequestAndParseEntity(getMappingsRequest,
265+
IndicesRequestConverters::getMappings,
266+
options,
267+
GetMappingsResponse::fromXContent,
268+
emptySet());
266269
}
267270

268271
/**
@@ -275,8 +278,60 @@ public GetMappingsResponse getMapping(GetMappingsRequest getMappingsRequest, Req
275278
*/
276279
public void getMappingAsync(GetMappingsRequest getMappingsRequest, RequestOptions options,
277280
ActionListener<GetMappingsResponse> listener) {
278-
restHighLevelClient.performRequestAsyncAndParseEntity(getMappingsRequest, IndicesRequestConverters::getMappings, options,
279-
GetMappingsResponse::fromXContent, listener, emptySet());
281+
restHighLevelClient.performRequestAsyncAndParseEntity(getMappingsRequest,
282+
IndicesRequestConverters::getMappings,
283+
options,
284+
GetMappingsResponse::fromXContent,
285+
listener,
286+
emptySet());
287+
}
288+
289+
/**
290+
* Retrieves the mappings on an index or indices using the Get Mapping API.
291+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html">
292+
* Get Mapping API on elastic.co</a>
293+
* @param getMappingsRequest the request
294+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
295+
* @return the response
296+
* @throws IOException in case there is a problem sending the request or parsing back the response
297+
*
298+
* @deprecated This method uses old request and response objects which still refer to types, a deprecated
299+
* feature. The method {@link #getMapping(GetMappingsRequest, RequestOptions)} should be used instead, which
300+
* accepts a new request object.
301+
*/
302+
@Deprecated
303+
public org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse getMapping(
304+
org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest,
305+
RequestOptions options) throws IOException {
306+
return restHighLevelClient.performRequestAndParseEntity(getMappingsRequest,
307+
IndicesRequestConverters::getMappings,
308+
options,
309+
org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse::fromXContent,
310+
emptySet());
311+
}
312+
313+
/**
314+
* Asynchronously retrieves the mappings on an index on indices using the Get Mapping API.
315+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html">
316+
* Get Mapping API on elastic.co</a>
317+
* @param getMappingsRequest the request
318+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
319+
* @param listener the listener to be notified upon request completion
320+
*
321+
* @deprecated This method uses old request and response objects which still refer to types, a deprecated feature.
322+
* The method {@link #getMapping(GetMappingsRequest, RequestOptions)} should be used instead, which accepts a new
323+
* request object.
324+
*/
325+
@Deprecated
326+
public void getMappingAsync(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest,
327+
RequestOptions options,
328+
ActionListener<org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse> listener) {
329+
restHighLevelClient.performRequestAsyncAndParseEntity(getMappingsRequest,
330+
IndicesRequestConverters::getMappings,
331+
options,
332+
org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse::fromXContent,
333+
listener,
334+
emptySet());
280335
}
281336

282337
/**
@@ -288,8 +343,9 @@ public void getMappingAsync(GetMappingsRequest getMappingsRequest, RequestOption
288343
* @return the response
289344
* @throws IOException in case there is a problem sending the request or parsing back the response
290345
*
291-
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
292-
* {@link #getFieldMapping(GetFieldMappingsRequest, RequestOptions)} should be used instead, which accepts a new request object.
346+
* @deprecated This method uses old request and response objects which still refer to types, a deprecated feature.
347+
* The method {@link #getFieldMapping(GetFieldMappingsRequest, RequestOptions)} should be used instead, which
348+
* accepts a new request object.
293349
*/
294350
@Deprecated
295351
public org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse getFieldMapping(
@@ -307,9 +363,9 @@ public org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRespon
307363
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
308364
* @param listener the listener to be notified upon request completion
309365
*
310-
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The
311-
* method {@link #getFieldMappingAsync(GetFieldMappingsRequest, RequestOptions, ActionListener)} should be used instead,
312-
* which accepts a new request object.
366+
* @deprecated This method uses old request and response objects which still refer to types, a deprecated feature.
367+
* The method {@link #getFieldMappingAsync(GetFieldMappingsRequest, RequestOptions, ActionListener)} should be
368+
* used instead, which accepts a new request object.
313369
*/
314370
@Deprecated
315371
public void getFieldMappingAsync(org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest getFieldMappingsRequest,

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
3636
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
3737
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
38-
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
3938
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
4039
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
4140
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
@@ -49,6 +48,7 @@
4948
import org.elasticsearch.client.indices.CreateIndexRequest;
5049
import org.elasticsearch.client.indices.FreezeIndexRequest;
5150
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
51+
import org.elasticsearch.client.indices.GetMappingsRequest;
5252
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
5353
import org.elasticsearch.client.indices.PutMappingRequest;
5454
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
@@ -148,6 +148,7 @@ static Request putMapping(PutMappingRequest putMappingRequest) throws IOExceptio
148148
return request;
149149
}
150150

151+
@Deprecated
151152
static Request putMapping(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest putMappingRequest) throws IOException {
152153
// The concreteIndex is an internal concept, not applicable to requests made over the REST API.
153154
if (putMappingRequest.getConcreteIndex() != null) {
@@ -166,7 +167,21 @@ static Request putMapping(org.elasticsearch.action.admin.indices.mapping.put.Put
166167
return request;
167168
}
168169

169-
static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOException {
170+
static Request getMappings(GetMappingsRequest getMappingsRequest) {
171+
String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices();
172+
173+
Request request = new Request(HttpGet.METHOD_NAME, RequestConverters.endpoint(indices, "_mapping"));
174+
175+
RequestConverters.Params parameters = new RequestConverters.Params(request);
176+
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout());
177+
parameters.withIndicesOptions(getMappingsRequest.indicesOptions());
178+
parameters.withLocal(getMappingsRequest.local());
179+
180+
return request;
181+
}
182+
183+
@Deprecated
184+
static Request getMappings(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest) {
170185
String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices();
171186
String[] types = getMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.types();
172187

@@ -176,6 +191,7 @@ static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOExcep
176191
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout());
177192
parameters.withIndicesOptions(getMappingsRequest.indicesOptions());
178193
parameters.withLocal(getMappingsRequest.local());
194+
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
179195

180196
return request;
181197
}
@@ -201,6 +217,7 @@ static Request getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest)
201217
return request;
202218
}
203219

220+
@Deprecated
204221
static Request getFieldMapping(org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest getFieldMappingsRequest) {
205222
String[] indices = getFieldMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.indices();
206223
String[] types = getFieldMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.types();
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client.indices;
21+
22+
import org.elasticsearch.action.support.IndicesOptions;
23+
import org.elasticsearch.client.TimedRequest;
24+
import org.elasticsearch.common.Strings;
25+
26+
public class GetMappingsRequest extends TimedRequest {
27+
28+
private boolean local = false;
29+
private boolean includeDefaults = false;
30+
private String[] indices = Strings.EMPTY_ARRAY;
31+
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen();
32+
33+
/**
34+
* Indicates whether the receiving node should operate based on local index information or
35+
* forward requests, where needed, to other nodes. If running locally, request will not
36+
* raise errors if local index information is missing.
37+
*/
38+
public GetMappingsRequest local(boolean local) {
39+
this.local = local;
40+
return this;
41+
}
42+
43+
public boolean local() {
44+
return local;
45+
}
46+
47+
public GetMappingsRequest indices(String... indices) {
48+
this.indices = indices;
49+
return this;
50+
}
51+
52+
public GetMappingsRequest indicesOptions(IndicesOptions indicesOptions) {
53+
this.indicesOptions = indicesOptions;
54+
return this;
55+
}
56+
57+
public String[] indices() {
58+
return indices;
59+
}
60+
61+
public IndicesOptions indicesOptions() {
62+
return indicesOptions;
63+
}
64+
65+
public boolean includeDefaults() {
66+
return includeDefaults;
67+
}
68+
69+
/** Indicates whether default mapping settings should be returned */
70+
public GetMappingsRequest includeDefaults(boolean includeDefaults) {
71+
this.includeDefaults = includeDefaults;
72+
return this;
73+
}
74+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client.indices;
21+
22+
import org.elasticsearch.cluster.metadata.MappingMetaData;
23+
import org.elasticsearch.common.ParseField;
24+
import org.elasticsearch.common.xcontent.XContentParser;
25+
import org.elasticsearch.common.xcontent.XContentParserUtils;
26+
import org.elasticsearch.index.mapper.MapperService;
27+
28+
import java.io.IOException;
29+
import java.util.HashMap;
30+
import java.util.Map;
31+
32+
public class GetMappingsResponse {
33+
34+
static final ParseField MAPPINGS = new ParseField("mappings");
35+
36+
private Map<String, MappingMetaData> mappings;
37+
38+
public GetMappingsResponse(Map<String, MappingMetaData> mappings) {
39+
this.mappings = mappings;
40+
}
41+
42+
public Map<String, MappingMetaData> mappings() {
43+
return mappings;
44+
}
45+
46+
public static GetMappingsResponse fromXContent(XContentParser parser) throws IOException {
47+
if (parser.currentToken() == null) {
48+
parser.nextToken();
49+
}
50+
51+
XContentParserUtils.ensureExpectedToken(parser.currentToken(),
52+
XContentParser.Token.START_OBJECT,
53+
parser::getTokenLocation);
54+
55+
Map<String, Object> parts = parser.map();
56+
57+
Map<String, MappingMetaData> mappings = new HashMap<>();
58+
for (Map.Entry<String, Object> entry : parts.entrySet()) {
59+
String indexName = entry.getKey();
60+
assert entry.getValue() instanceof Map : "expected a map as type mapping, but got: " + entry.getValue().getClass();
61+
62+
@SuppressWarnings("unchecked")
63+
final Map<String, Object> fieldMappings = (Map<String, Object>) ((Map<String, ?>) entry.getValue())
64+
.get(MAPPINGS.getPreferredName());
65+
66+
mappings.put(indexName, new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, fieldMappings));
67+
}
68+
69+
return new GetMappingsResponse(mappings);
70+
}
71+
}

0 commit comments

Comments
 (0)