Skip to content

Commit 08ee9b6

Browse files
committed
Merge branch 'master' into ccr
* master: Add get field mappings to High Level REST API Client (#31423) [DOCS] Updates Watcher examples for code testing (#31152) TEST: Add bwc recovery tests with synced-flush index [DOCS] Move sql to docs (#31474) [DOCS] Move monitoring to docs folder (#31477) Core: Combine doExecute methods in TransportAction (#31517) IndexShard should not return null stats (#31528) fix repository update with the same settings but different type (#31458) Fix Mockito trying to mock IOException that isn't thrown by method (#31433) (#31527) Node selector per client rather than per request (#31471) Core: Combine messageRecieved methods in TransportRequestHandler (#31519) Upgrade to Lucene 7.4.0. (#31529) [ML] Add ML filter update API (#31437) Allow multiple unicast host providers (#31509) Avoid deprecation warning when running the ML datafeed extractor. (#31463) REST high-level client: add simulate pipeline API (#31158) Get Mapping API to honour allow_no_indices and ignore_unavailable (#31507) [PkiRealm] Invalidate cache on role mappings change (#31510) [Security] Check auth scheme case insensitively (#31490) In NumberFieldType equals and hashCode, make sure that NumberType is taken into account. (#31514) [DOCS] Fix REST tests in SQL docs [DOCS] Add code snippet testing in more ML APIs (#31339) Core: Remove ThreadPool from base TransportAction (#31492) [DOCS] Remove fixed file from build.gradle Rename createNewTranslog to fileBasedRecovery (#31508) Test: Skip assertion on windows [DOCS] Creates field and document level security overview (#30937) [DOCS] Significantly improve SQL docs [DOCS] Move migration APIs to docs (#31473) Core: Convert TransportAction.execute uses to client calls (#31487) Return transport addresses from UnicastHostsProvider (#31426) Ensure local addresses aren't null (#31440) Remove unused generic type for client execute method (#31444) Introduce http and tcp server channels (#31446)
2 parents 601ea76 + b7ef75f commit 08ee9b6

File tree

484 files changed

+5981
-3026
lines changed

Some content is hidden

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

484 files changed

+5981
-3026
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.4.0-snapshot-518d303506
2+
lucene = 7.4.0
33

44
# optional dependencies
55
spatial4j = 0.7

client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/TransportNoopBulkAction.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
package org.elasticsearch.plugin.noop.action.bulk;
2020

2121
import org.elasticsearch.action.ActionListener;
22-
import org.elasticsearch.action.DocWriteResponse;
2322
import org.elasticsearch.action.DocWriteRequest;
23+
import org.elasticsearch.action.DocWriteResponse;
2424
import org.elasticsearch.action.bulk.BulkItemResponse;
2525
import org.elasticsearch.action.bulk.BulkRequest;
2626
import org.elasticsearch.action.bulk.BulkResponse;
@@ -30,21 +30,20 @@
3030
import org.elasticsearch.common.inject.Inject;
3131
import org.elasticsearch.common.settings.Settings;
3232
import org.elasticsearch.index.shard.ShardId;
33-
import org.elasticsearch.threadpool.ThreadPool;
33+
import org.elasticsearch.tasks.Task;
3434
import org.elasticsearch.transport.TransportService;
3535

3636
public class TransportNoopBulkAction extends HandledTransportAction<BulkRequest, BulkResponse> {
3737
private static final BulkItemResponse ITEM_RESPONSE = new BulkItemResponse(1, DocWriteRequest.OpType.UPDATE,
3838
new UpdateResponse(new ShardId("mock", "", 1), "mock_type", "1", 1L, DocWriteResponse.Result.CREATED));
3939

4040
@Inject
41-
public TransportNoopBulkAction(Settings settings, ThreadPool threadPool, TransportService transportService,
42-
ActionFilters actionFilters) {
43-
super(settings, NoopBulkAction.NAME, threadPool, transportService, actionFilters, BulkRequest::new);
41+
public TransportNoopBulkAction(Settings settings, TransportService transportService, ActionFilters actionFilters) {
42+
super(settings, NoopBulkAction.NAME, transportService, actionFilters, BulkRequest::new);
4443
}
4544

4645
@Override
47-
protected void doExecute(BulkRequest request, ActionListener<BulkResponse> listener) {
46+
protected void doExecute(Task task, BulkRequest request, ActionListener<BulkResponse> listener) {
4847
final int itemCount = request.requests().size();
4948
// simulate at least a realistic amount of data that gets serialized
5049
BulkItemResponse[] bulkItemResponses = new BulkItemResponse[itemCount];

client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/TransportNoopSearchAction.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,25 @@
2727
import org.elasticsearch.common.inject.Inject;
2828
import org.elasticsearch.common.io.stream.Writeable;
2929
import org.elasticsearch.common.settings.Settings;
30-
import org.elasticsearch.search.aggregations.InternalAggregations;
3130
import org.elasticsearch.search.SearchHit;
3231
import org.elasticsearch.search.SearchHits;
32+
import org.elasticsearch.search.aggregations.InternalAggregations;
3333
import org.elasticsearch.search.internal.InternalSearchResponse;
3434
import org.elasticsearch.search.profile.SearchProfileShardResults;
3535
import org.elasticsearch.search.suggest.Suggest;
36-
import org.elasticsearch.threadpool.ThreadPool;
36+
import org.elasticsearch.tasks.Task;
3737
import org.elasticsearch.transport.TransportService;
3838

3939
import java.util.Collections;
4040

4141
public class TransportNoopSearchAction extends HandledTransportAction<SearchRequest, SearchResponse> {
4242
@Inject
43-
public TransportNoopSearchAction(Settings settings, ThreadPool threadPool, TransportService transportService,
44-
ActionFilters actionFilters) {
45-
super(settings, NoopSearchAction.NAME, threadPool, transportService, actionFilters,
46-
(Writeable.Reader<SearchRequest>) SearchRequest::new);
43+
public TransportNoopSearchAction(Settings settings, TransportService transportService, ActionFilters actionFilters) {
44+
super(settings, NoopSearchAction.NAME, transportService, actionFilters, (Writeable.Reader<SearchRequest>) SearchRequest::new);
4745
}
4846

4947
@Override
50-
protected void doExecute(SearchRequest request, ActionListener<SearchResponse> listener) {
48+
protected void doExecute(Task task, SearchRequest request, ActionListener<SearchResponse> listener) {
5149
listener.onResponse(new SearchResponse(new InternalSearchResponse(
5250
new SearchHits(
5351
new SearchHit[0], 0L, 0.0f),

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

+31
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
3838
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
3939
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
40+
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
41+
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
4042
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
4143
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
4244
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
@@ -188,6 +190,35 @@ public void getMappingsAsync(GetMappingsRequest getMappingsRequest, RequestOptio
188190
GetMappingsResponse::fromXContent, listener, emptySet());
189191
}
190192

193+
/**
194+
* Retrieves the field mappings on an index or indices using the Get Field Mapping API.
195+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html">
196+
* Get Field Mapping API on elastic.co</a>
197+
* @param getFieldMappingsRequest the request
198+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
199+
* @return the response
200+
* @throws IOException in case there is a problem sending the request or parsing back the response
201+
*/
202+
public GetFieldMappingsResponse getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest,
203+
RequestOptions options) throws IOException {
204+
return restHighLevelClient.performRequestAndParseEntity(getFieldMappingsRequest, RequestConverters::getFieldMapping, options,
205+
GetFieldMappingsResponse::fromXContent, emptySet());
206+
}
207+
208+
/**
209+
* Asynchronously retrieves the field mappings on an index on indices using the Get Field Mapping API.
210+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html">
211+
* Get Field Mapping API on elastic.co</a>
212+
* @param getFieldMappingsRequest the request
213+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
214+
* @param listener the listener to be notified upon request completion
215+
*/
216+
public void getFieldMappingAsync(GetFieldMappingsRequest getFieldMappingsRequest, RequestOptions options,
217+
ActionListener<GetFieldMappingsResponse> listener) {
218+
restHighLevelClient.performRequestAsyncAndParseEntity(getFieldMappingsRequest, RequestConverters::getFieldMapping, options,
219+
GetFieldMappingsResponse::fromXContent, listener, emptySet());
220+
}
221+
191222
/**
192223
* Updates aliases using the Index Aliases API.
193224
* 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/IngestClient.java

+35
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.elasticsearch.action.ingest.GetPipelineRequest;
2525
import org.elasticsearch.action.ingest.GetPipelineResponse;
2626
import org.elasticsearch.action.ingest.PutPipelineRequest;
27+
import org.elasticsearch.action.ingest.SimulatePipelineRequest;
28+
import org.elasticsearch.action.ingest.SimulatePipelineResponse;
2729
import org.elasticsearch.action.ingest.WritePipelineResponse;
2830

2931
import java.io.IOException;
@@ -125,4 +127,37 @@ public void deletePipelineAsync(DeletePipelineRequest request, RequestOptions op
125127
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::deletePipeline, options,
126128
WritePipelineResponse::fromXContent, listener, emptySet());
127129
}
130+
131+
/**
132+
* Simulate a pipeline on a set of documents provided in the request
133+
* <p>
134+
* See
135+
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/simulate-pipeline-api.html">
136+
* Simulate Pipeline API on elastic.co</a>
137+
* @param request the request
138+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
139+
* @return the response
140+
* @throws IOException in case there is a problem sending the request or parsing back the response
141+
*/
142+
public SimulatePipelineResponse simulatePipeline(SimulatePipelineRequest request, RequestOptions options) throws IOException {
143+
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::simulatePipeline, options,
144+
SimulatePipelineResponse::fromXContent, emptySet());
145+
}
146+
147+
/**
148+
* Asynchronously simulate a pipeline on a set of documents provided in the request
149+
* <p>
150+
* See
151+
* <a href="https://www.elastic.co/guide/en/elasticsearch/reference/master/simulate-pipeline-api.html">
152+
* Simulate Pipeline API on elastic.co</a>
153+
* @param request the request
154+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
155+
* @param listener the listener to be notified upon request completion
156+
*/
157+
public void simulatePipelineAsync(SimulatePipelineRequest request,
158+
RequestOptions options,
159+
ActionListener<SimulatePipelineResponse> listener) {
160+
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::simulatePipeline, options,
161+
SimulatePipelineResponse::fromXContent, listener, emptySet());
162+
}
128163
}

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

+35
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
5151
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
5252
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
53+
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
5354
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
5455
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
5556
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
@@ -71,6 +72,7 @@
7172
import org.elasticsearch.action.ingest.DeletePipelineRequest;
7273
import org.elasticsearch.action.ingest.PutPipelineRequest;
7374
import org.elasticsearch.action.ingest.GetPipelineRequest;
75+
import org.elasticsearch.action.ingest.SimulatePipelineRequest;
7476
import org.elasticsearch.action.search.ClearScrollRequest;
7577
import org.elasticsearch.action.search.MultiSearchRequest;
7678
import org.elasticsearch.action.search.SearchRequest;
@@ -229,6 +231,25 @@ static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOExcep
229231
return request;
230232
}
231233

234+
static Request getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest) throws IOException {
235+
String[] indices = getFieldMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.indices();
236+
String[] types = getFieldMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.types();
237+
String[] fields = getFieldMappingsRequest.fields() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.fields();
238+
239+
String endpoint = new EndpointBuilder().addCommaSeparatedPathParts(indices)
240+
.addPathPartAsIs("_mapping").addCommaSeparatedPathParts(types)
241+
.addPathPartAsIs("field").addCommaSeparatedPathParts(fields)
242+
.build();
243+
244+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
245+
246+
Params parameters = new Params(request);
247+
parameters.withIndicesOptions(getFieldMappingsRequest.indicesOptions());
248+
parameters.withIncludeDefaults(getFieldMappingsRequest.includeDefaults());
249+
parameters.withLocal(getFieldMappingsRequest.local());
250+
return request;
251+
}
252+
232253
static Request refresh(RefreshRequest refreshRequest) {
233254
String[] indices = refreshRequest.indices() == null ? Strings.EMPTY_ARRAY : refreshRequest.indices();
234255
Request request = new Request(HttpPost.METHOD_NAME, endpoint(indices, "_refresh"));
@@ -886,6 +907,20 @@ static Request validateQuery(ValidateQueryRequest validateQueryRequest) throws I
886907
return request;
887908
}
888909

910+
static Request simulatePipeline(SimulatePipelineRequest simulatePipelineRequest) throws IOException {
911+
EndpointBuilder builder = new EndpointBuilder().addPathPartAsIs("_ingest/pipeline");
912+
if (simulatePipelineRequest.getId() != null && !simulatePipelineRequest.getId().isEmpty()) {
913+
builder.addPathPart(simulatePipelineRequest.getId());
914+
}
915+
builder.addPathPartAsIs("_simulate");
916+
String endpoint = builder.build();
917+
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
918+
Params params = new Params(request);
919+
params.putParam("verbose", Boolean.toString(simulatePipelineRequest.isVerbose()));
920+
request.setEntity(createEntity(simulatePipelineRequest, REQUEST_BODY_CONTENT_TYPE));
921+
return request;
922+
}
923+
889924
static Request getAlias(GetAliasesRequest getAliasesRequest) {
890925
String[] indices = getAliasesRequest.indices() == null ? Strings.EMPTY_ARRAY : getAliasesRequest.indices();
891926
String[] aliases = getAliasesRequest.aliases() == null ? Strings.EMPTY_ARRAY : getAliasesRequest.aliases();

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ private HighLevelClient(RestClient restClient) {
8585
}
8686
}
8787

88-
protected static XContentBuilder buildRandomXContentPipeline() throws IOException {
89-
XContentType xContentType = randomFrom(XContentType.values());
90-
XContentBuilder pipelineBuilder = XContentBuilder.builder(xContentType.xContent());
88+
protected static XContentBuilder buildRandomXContentPipeline(XContentBuilder pipelineBuilder) throws IOException {
9189
pipelineBuilder.startObject();
9290
{
9391
pipelineBuilder.field(Pipeline.DESCRIPTION_KEY, "some random set of processors");
@@ -114,6 +112,12 @@ protected static XContentBuilder buildRandomXContentPipeline() throws IOExceptio
114112
return pipelineBuilder;
115113
}
116114

115+
protected static XContentBuilder buildRandomXContentPipeline() throws IOException {
116+
XContentType xContentType = randomFrom(XContentType.values());
117+
XContentBuilder pipelineBuilder = XContentBuilder.builder(xContentType.xContent());
118+
return buildRandomXContentPipeline(pipelineBuilder);
119+
}
120+
117121
protected static void createPipeline(String pipelineId) throws IOException {
118122
XContentBuilder builder = buildRandomXContentPipeline();
119123
createPipeline(new PutPipelineRequest(pipelineId, BytesReference.bytes(builder), builder.contentType()));

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

+38
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;
@@ -74,6 +76,7 @@
7476
import org.elasticsearch.cluster.metadata.IndexMetaData;
7577
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
7678
import org.elasticsearch.common.ValidationException;
79+
import org.elasticsearch.common.bytes.BytesArray;
7780
import org.elasticsearch.common.settings.Setting;
7881
import org.elasticsearch.common.settings.Settings;
7982
import org.elasticsearch.common.unit.ByteSizeUnit;
@@ -378,6 +381,41 @@ public void testGetMapping() throws IOException {
378381
assertThat(mappings, equalTo(expected));
379382
}
380383

384+
public void testGetFieldMapping() throws IOException {
385+
String indexName = "test";
386+
createIndex(indexName, Settings.EMPTY);
387+
388+
PutMappingRequest putMappingRequest = new PutMappingRequest(indexName);
389+
putMappingRequest.type("_doc");
390+
XContentBuilder mappingBuilder = JsonXContent.contentBuilder();
391+
mappingBuilder.startObject().startObject("properties").startObject("field");
392+
mappingBuilder.field("type", "text");
393+
mappingBuilder.endObject().endObject().endObject();
394+
putMappingRequest.source(mappingBuilder);
395+
396+
PutMappingResponse putMappingResponse =
397+
execute(putMappingRequest, highLevelClient().indices()::putMapping, highLevelClient().indices()::putMappingAsync);
398+
assertTrue(putMappingResponse.isAcknowledged());
399+
400+
GetFieldMappingsRequest getFieldMappingsRequest = new GetFieldMappingsRequest()
401+
.indices(indexName)
402+
.types("_doc")
403+
.fields("field");
404+
405+
GetFieldMappingsResponse getFieldMappingsResponse =
406+
execute(getFieldMappingsRequest,
407+
highLevelClient().indices()::getFieldMapping,
408+
highLevelClient().indices()::getFieldMappingAsync);
409+
410+
final Map<String, GetFieldMappingsResponse.FieldMappingMetaData> fieldMappingMap =
411+
getFieldMappingsResponse.mappings().get(indexName).get("_doc");
412+
413+
final GetFieldMappingsResponse.FieldMappingMetaData metaData =
414+
new GetFieldMappingsResponse.FieldMappingMetaData("field",
415+
new BytesArray("{\"field\":{\"type\":\"text\"}}"));
416+
assertThat(fieldMappingMap, equalTo(Collections.singletonMap("field", metaData)));
417+
}
418+
381419
public void testDeleteIndex() throws IOException {
382420
{
383421
// Delete index if exists

0 commit comments

Comments
 (0)