diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index d52ae7b35538b..6b265564b3509 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -861,8 +861,8 @@ public void testApiNamingConventions() throws Exception { "indices.create_data_stream", "indices.get_data_streams", "indices.delete_data_stream", - "clear_reader", - "open_reader" + "open_search_context", + "close_search_context", }; //These API are not required for high-level client feature completeness String[] notRequiredApi = new String[] { diff --git a/docs/reference/search/request/reader_context.asciidoc b/docs/reference/search/search_context.asciidoc similarity index 54% rename from docs/reference/search/request/reader_context.asciidoc rename to docs/reference/search/search_context.asciidoc index 6fb397fceceb2..7c3da5cedc865 100644 --- a/docs/reference/search/request/reader_context.asciidoc +++ b/docs/reference/search/search_context.asciidoc @@ -1,24 +1,24 @@ -[[reader-context]] -==== Reader Context +[[search-context]] +==== Search Context By default, a search request executes against the latest point in time readers of the target indices. Sometimes it's preferred to execute multiple search requests using the same point in time readers. For example, the combined result of the initial and subsequent search_after requests is more consistent if they use the same point in time -readers. +readers. This can be done by using a single search context for all search requests. -Point in time readers must be opened in a separate step before being used in subsequent +A search context must be opened in a separate step before being used in subsequent search requests. The keep_alive parameter tells Elasticsearch how long it should keep -the ``reader_context'' alive, e.g. `?keep_alive=5m`. +the seach context alive, e.g. `?keep_alive=5m`. [source,console] -------------------------------------------------- -POST /twitter/_open_reader?keep_alive=1m +POST /twitter/_search_context?keep_alive=1m -------------------------------------------------- // TEST[setup:twitter] -The result from the above request includes a `reader_id`, which should -be passed to the `id` of the `reader` parameter of a search request. +The result from the above request includes a `id`, which should +be passed to the `id` of the `search_context` parameter of a search request. POST /_search <1> { @@ -28,46 +28,46 @@ POST /_search <1> "title" : "elasticsearch" } }, - "reader": { + "search_context": { "id": "46ToAwEHdHdpdHRlchZSa1dRZDFELVNLbTZkQVJudUtGMFFnAAAWNVAwS09JWTdTRUdibWE1ZC1id0tjQRRURnhPWjNFQmI3bmVOeVZReS1tRAAAAAAAAAAB", <2> "keep_alive": "1m" <3> } } -<1> A search request with `reader.id` must not specify `index`, `routing`, -and `preferences` as these parameters are copied from the `reader.id`. -<2> The `reader.id` parameter tells Elasticsearch to execute the request using -the point-in-time readers from this id. -<3> The `reader.keep_alive` parameter tells Elasticsearch how long it should extend -the time to live of these readers. - -IMPORTANT: The open_reader request and each subsequent search request can return -different `reader_id`; thus always use the most recently received `reader_id` -for the next search request. - -[[reader-keep-alive]] -===== Keeping the reader context alive -The `keep_alive` parameter (passed to a `open_reader` request and search -request) extends the time to live of open reader contexts. The value +<1> A search request with `search_context` must not specify `index`, `routing`, +and `preferences` as these parameters are copied from the `search_context`. +<2> The `id` parameter tells Elasticsearch to execute the request using +the point-in-time readers from this search context id. +<3> The `keep_alive` parameter tells Elasticsearch how long it should extend +the time to live of the search context + +IMPORTANT: The open search context request and each subsequent search request can +return different `id`; thus always use the most recently received `id` for the +next search request. + +[[search-context-keep-alive]] +===== Keeping the search context alive +The `keep_alive` parameter, which is passed to a open search context request and +search request, extends the time to live of the search context. The value (e.g. `1m`, see <>) does not need to be long enough to process all data -- it just needs to be long enough for the next request. Normally, the background merge process optimizes the index by merging together smaller segments to create new, bigger segments. Once the smaller segments are -no longer needed they are deleted. However, open reader contexts prevents the +no longer needed they are deleted. However, open search contexts prevents the old segments from being deleted since they are still in use. TIP: Keeping older segments alive means that more disk space and file handles are needed. Ensure that you have configured your nodes to have ample free file handles. See <>. -Additionally, if a segment contains deleted or updated documents then the reader +Additionally, if a segment contains deleted or updated documents then the search context must keep track of whether each document in the segment was live at the time of the initial search request. Ensure that your nodes have sufficient heap -space if you have many open reader contexts on an index that is subject to ongoing +space if you have many open search contexts on an index that is subject to ongoing deletes or updates. -You can check how many reader contexts are open with the +You can check how many search contexts are open with the <>: [source,console] @@ -75,16 +75,16 @@ You can check how many reader contexts are open with the GET /_nodes/stats/indices/search --------------------------------------- -===== Clear reader API +===== Close search context API -Reader contexts are automatically closed when the `reader.keep_alive` has -been elapsed. However keeping readers open has a cost, as discussed in the -<> so readers should be explicitly -closed as soon as they are no longer used in search requests. +Search contexts are automatically closed when the `keep_alive` has +been elapsed. However keeping search contexts as a cost, as discussed in the +<> so search context should be +explicitly closed as soon as they are no longer used in search requests. [source,console] --------------------------------------- -DELETE /_search/reader +DELETE /_search_context { "id" : "46ToAwEHdHdpdHRlchZSa1dRZDFELVNLbTZkQVJudUtGMFFnAAAWNVAwS09JWTdTRUdibWE1ZC1id0tjQRRURnhPWjNFQmI3bmVOeVZReS1tRAAAAAAAAAAB" } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/clear_reader.json b/rest-api-spec/src/main/resources/rest-api-spec/api/close_search_context.json similarity index 57% rename from rest-api-spec/src/main/resources/rest-api-spec/api/clear_reader.json rename to rest-api-spec/src/main/resources/rest-api-spec/api/close_search_context.json index 0799d22a81e0d..87c97127fa616 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/clear_reader.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/close_search_context.json @@ -1,14 +1,14 @@ { - "clear_reader":{ + "close_search_context":{ "documentation":{ - "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/reader-context.html", - "description":"Explicitly close the point in time readers" + "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/search-context.html", + "description":"Close a search context" }, "stability":"beta", "url":{ "paths":[ { - "path":"/_search/reader", + "path":"/_search_context", "methods":[ "DELETE" ] @@ -17,7 +17,7 @@ }, "params":{}, "body":{ - "description": "point in time readers to clear" + "description": "a search context to close" } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/open_reader.json b/rest-api-spec/src/main/resources/rest-api-spec/api/open_search_context.json similarity index 76% rename from rest-api-spec/src/main/resources/rest-api-spec/api/open_reader.json rename to rest-api-spec/src/main/resources/rest-api-spec/api/open_search_context.json index 435e40e8d9281..4d3fb8c5f632b 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/open_reader.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/open_search_context.json @@ -1,27 +1,27 @@ { - "open_reader":{ + "open_search_context":{ "documentation":{ - "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/reader-context.html", - "description":"Open and keep point-in-time readers that can be used in subsequent search requests" + "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/search-context.html", + "description":"Open a search context that can be used in subsequent searches" }, "stability":"beta", "url":{ "paths":[ { - "path":"/_open_reader", + "path":"/_search_context", "methods":[ "POST" ] }, { - "path":"/{index}/_open_reader", + "path":"/{index}/_search_context", "methods":[ "POST" ], "parts":{ "index":{ "type":"list", - "description":"A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices" + "description":"A comma-separated list of index names to open search context; use `_all` or empty string to perform the operation on all indices" } } } @@ -54,7 +54,7 @@ }, "keep_alive": { "type": "string", - "description": "Specific the time to live for the point-in-time readers" + "description": "Specific the time to live for the search context" } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/330_reader_context.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/330_search_context.yml similarity index 81% rename from rest-api-spec/src/main/resources/rest-api-spec/test/search/330_reader_context.yml rename to rest-api-spec/src/main/resources/rest-api-spec/test/search/330_search_context.yml index 6da2ea1152ad9..253678dda9db2 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/330_reader_context.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/330_search_context.yml @@ -25,15 +25,15 @@ setup: index: test --- -"search with reader context": +"search context": - skip: version: " - 7.9.99" - reason: "reader context is introduced in 8.0" + reason: "search context is introduced in 8.0" - do: - open_reader: + open_search_context: index: test - keep_alive: 1m - - set: {reader_id: reader_id} + keep_alive: 5m + - set: {id: search_context_id} - do: search: @@ -44,8 +44,8 @@ setup: match: foo: bar sort: [{ age: desc }, { id: desc }] - reader: - id: "$reader_id" + search_context: + id: "$search_context_id" keep_alive: 1m - match: {hits.total: 3 } @@ -63,7 +63,7 @@ setup: indices.refresh: index: test - # search with the retaining readers + # search with the retaining search context - do: search: rest_total_hits_as_int: true @@ -74,8 +74,8 @@ setup: foo: bar sort: [{ age: desc }, { id: desc }] search_after: [24, 172] - reader: - id: "$reader_id" + search_context: + id: "$search_context_id" keep_alive: 1m - match: {hits.total: 3 } @@ -94,8 +94,8 @@ setup: foo: bar sort: [ { age: desc }, { id: desc } ] search_after: [18, 42] - reader: - id: "$reader_id" + search_context: + id: "$search_context_id" keep_alive: 1m - match: {hits.total: 3} @@ -114,14 +114,14 @@ setup: foo: bar sort: [{ age: desc }, { id: desc } ] search_after: [18, 1] - reader: - id: "$reader_id" + search_context: + id: "$search_context_id" keep_alive: 1m - match: {hits.total: 3} - length: {hits.hits: 0 } - do: - clear_reader: + close_search_context: body: - id: "$reader_id" + id: "$search_context_id" diff --git a/server/src/internalClusterTest/java/org/elasticsearch/search/searchafter/SearchWithReaderContextIT.java b/server/src/internalClusterTest/java/org/elasticsearch/search/searchafter/SearchWithReaderContextIT.java index ac166298a69e4..e597ea23e5847 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/search/searchafter/SearchWithReaderContextIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/search/searchafter/SearchWithReaderContextIT.java @@ -21,15 +21,15 @@ import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.admin.indices.stats.CommonStats; -import org.elasticsearch.action.search.ClearReaderAction; -import org.elasticsearch.action.search.ClearReaderRequest; -import org.elasticsearch.action.search.OpenReaderRequest; -import org.elasticsearch.action.search.OpenReaderResponse; +import org.elasticsearch.action.search.CloseSearchContextAction; +import org.elasticsearch.action.search.CloseSearchContextRequest; +import org.elasticsearch.action.search.OpenSearchContextRequest; +import org.elasticsearch.action.search.OpenSearchContextResponse; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.search.ShardSearchFailure; -import org.elasticsearch.action.search.TransportOpenReaderAction; +import org.elasticsearch.action.search.TransportOpenSearchContextAction; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -70,9 +70,9 @@ public void testBasic() { client().prepareIndex("test").setId(id).setSource("value", i).get(); } refresh("test"); - String readerId = openReaders(new String[]{"test"}, TimeValue.timeValueMinutes(2)); + String readerId = openSearchContext(new String[]{"test"}, TimeValue.timeValueMinutes(2)); SearchResponse resp1 = client().prepareSearch().setPreference(null).setReader(readerId, TimeValue.timeValueMinutes(2)).get(); - assertThat(resp1.getReaderId(), equalTo(readerId)); + assertThat(resp1.searchContextId(), equalTo(readerId)); assertHitCount(resp1, numDocs); int deletedDocs = 0; for (int i = 0; i < numDocs; i++) { @@ -90,13 +90,13 @@ public void testBasic() { } try { SearchResponse resp3 = client().prepareSearch().setPreference(null).setQuery(new MatchAllQueryBuilder()) - .setReader(resp1.getReaderId(), TimeValue.timeValueMinutes(2)) + .setReader(resp1.searchContextId(), TimeValue.timeValueMinutes(2)) .get(); assertNoFailures(resp3); assertHitCount(resp3, numDocs); - assertThat(resp3.getReaderId(), equalTo(readerId)); + assertThat(resp3.searchContextId(), equalTo(readerId)); } finally { - clearReaderId(readerId); + closeSearchContext(readerId); } } @@ -112,7 +112,7 @@ public void testMultipleIndices() { client().prepareIndex(index).setId(id).setSource("value", i).get(); } refresh(); - String readerId = openReaders(new String[]{"*"}, TimeValue.timeValueMinutes(2)); + String readerId = openSearchContext(new String[]{"*"}, TimeValue.timeValueMinutes(2)); SearchResponse resp1 = client().prepareSearch().setPreference(null).setReader(readerId, TimeValue.timeValueMinutes(2)).get(); assertNoFailures(resp1); assertHitCount(resp1, numDocs); @@ -129,11 +129,11 @@ public void testMultipleIndices() { assertHitCount(resp2, numDocs + moreDocs); SearchResponse resp3 = client().prepareSearch().setPreference(null) - .setReader(resp1.getReaderId(), TimeValue.timeValueMinutes(1)).get(); + .setReader(resp1.searchContextId(), TimeValue.timeValueMinutes(1)).get(); assertNoFailures(resp3); assertHitCount(resp3, numDocs); } finally { - clearReaderId(resp1.getReaderId()); + closeSearchContext(resp1.searchContextId()); } } @@ -145,7 +145,7 @@ public void testReaderIdNotFound() throws Exception { client().prepareIndex("index").setId(id).setSource("value", i).get(); } refresh(); - String readerId = openReaders(new String[]{"index"}, TimeValue.timeValueSeconds(5)); + String readerId = openSearchContext(new String[]{"index"}, TimeValue.timeValueSeconds(5)); SearchResponse resp1 = client().prepareSearch().setPreference(null) .setReader(readerId, TimeValue.timeValueMillis(randomIntBetween(0, 10))).get(); assertNoFailures(resp1); @@ -156,10 +156,10 @@ public void testReaderIdNotFound() throws Exception { assertThat(stats.search.getOpenContexts(), equalTo(0L)); }, 60, TimeUnit.SECONDS); } else { - clearReaderId(resp1.getReaderId()); + closeSearchContext(resp1.searchContextId()); } SearchPhaseExecutionException e = expectThrows(SearchPhaseExecutionException.class, - () -> client().prepareSearch().setPreference(null).setReader(resp1.getReaderId(), TimeValue.timeValueMinutes(1)).get()); + () -> client().prepareSearch().setPreference(null).setReader(resp1.searchContextId(), TimeValue.timeValueMinutes(1)).get()); for (ShardSearchFailure failure : e.shardFailures()) { assertThat(ExceptionsHelper.unwrapCause(failure.getCause()), instanceOf(SearchContextMissingException.class)); } @@ -181,7 +181,7 @@ public void testIndexNotFound() { client().prepareIndex("index-2").setId(id).setSource("value", i).get(); } refresh(); - String readerId = openReaders(new String[]{"index-*"}, TimeValue.timeValueMinutes(2)); + String readerId = openSearchContext(new String[]{"index-*"}, TimeValue.timeValueMinutes(2)); SearchResponse resp1 = client().prepareSearch().setPreference(null).setReader(readerId, TimeValue.timeValueMinutes(2)).get(); assertNoFailures(resp1); assertHitCount(resp1, index1 + index2); @@ -194,8 +194,8 @@ public void testIndexNotFound() { } expectThrows(IndexNotFoundException.class, () -> client().prepareSearch() .setPreference(null) - .setReader(resp1.getReaderId(), TimeValue.timeValueMinutes(1)).get()); - clearReaderId(resp1.getReaderId()); + .setReader(resp1.searchContextId(), TimeValue.timeValueMinutes(1)).get()); + closeSearchContext(resp1.searchContextId()); } public void testCanMatch() throws Exception { @@ -206,7 +206,7 @@ public void testCanMatch() throws Exception { assertAcked(prepareCreate("test").setSettings(settings) .setMapping("{\"properties\":{\"created_date\":{\"type\": \"date\", \"format\": \"yyyy-MM-dd\"}}}")); ensureGreen("test"); - String readerId = openReaders(new String[]{"test*"}, TimeValue.timeValueMinutes(2)); + String readerId = openSearchContext(new String[]{"test*"}, TimeValue.timeValueMinutes(2)); try { for (String node : internalCluster().nodesInclude("test")) { for (IndexService indexService : internalCluster().getInstance(IndicesService.class, node)) { @@ -234,17 +234,18 @@ public void testCanMatch() throws Exception { } } } finally { - clearReaderId(readerId); + closeSearchContext(readerId); } } - private String openReaders(String[] indices, TimeValue keepAlive) { - OpenReaderRequest request = new OpenReaderRequest(indices, OpenReaderRequest.DEFAULT_INDICES_OPTIONS, keepAlive, null, null); - final OpenReaderResponse response = client().execute(TransportOpenReaderAction.INSTANCE, request).actionGet(); - return response.getReaderId(); + private String openSearchContext(String[] indices, TimeValue keepAlive) { + OpenSearchContextRequest request = + new OpenSearchContextRequest(indices, OpenSearchContextRequest.DEFAULT_INDICES_OPTIONS, keepAlive, null, null); + final OpenSearchContextResponse response = client().execute(TransportOpenSearchContextAction.INSTANCE, request).actionGet(); + return response.getSearchContextId(); } - private void clearReaderId(String readerId) { - client().execute(ClearReaderAction.INSTANCE, new ClearReaderRequest(readerId)).actionGet(); + private void closeSearchContext(String readerId) { + client().execute(CloseSearchContextAction.INSTANCE, new CloseSearchContextRequest(readerId)).actionGet(); } } diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index 9dc7c09d5decb..9867ddc237cb3 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -109,9 +109,6 @@ import org.elasticsearch.action.admin.indices.close.TransportVerifyShardBeforeCloseAction; import org.elasticsearch.action.admin.indices.create.CreateIndexAction; import org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction; -import org.elasticsearch.action.admin.indices.datastream.CreateDataStreamAction; -import org.elasticsearch.action.admin.indices.datastream.DeleteDataStreamAction; -import org.elasticsearch.action.admin.indices.datastream.GetDataStreamsAction; import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction; import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction; import org.elasticsearch.action.admin.indices.flush.FlushAction; @@ -205,15 +202,15 @@ import org.elasticsearch.action.ingest.SimulatePipelineTransportAction; import org.elasticsearch.action.main.MainAction; import org.elasticsearch.action.main.TransportMainAction; -import org.elasticsearch.action.search.ClearReaderAction; +import org.elasticsearch.action.search.CloseSearchContextAction; import org.elasticsearch.action.search.ClearScrollAction; import org.elasticsearch.action.search.MultiSearchAction; import org.elasticsearch.action.search.SearchAction; import org.elasticsearch.action.search.SearchScrollAction; -import org.elasticsearch.action.search.TransportClearReaderAction; +import org.elasticsearch.action.search.TransportCloseSearchContextAction; import org.elasticsearch.action.search.TransportClearScrollAction; import org.elasticsearch.action.search.TransportMultiSearchAction; -import org.elasticsearch.action.search.TransportOpenReaderAction; +import org.elasticsearch.action.search.TransportOpenSearchContextAction; import org.elasticsearch.action.search.TransportSearchAction; import org.elasticsearch.action.search.TransportSearchScrollAction; import org.elasticsearch.action.support.ActionFilters; @@ -367,12 +364,12 @@ import org.elasticsearch.rest.action.ingest.RestGetPipelineAction; import org.elasticsearch.rest.action.ingest.RestPutPipelineAction; import org.elasticsearch.rest.action.ingest.RestSimulatePipelineAction; -import org.elasticsearch.rest.action.search.RestClearReaderAction; +import org.elasticsearch.rest.action.search.RestCloseSearchContextAction; import org.elasticsearch.rest.action.search.RestClearScrollAction; import org.elasticsearch.rest.action.search.RestCountAction; import org.elasticsearch.rest.action.search.RestExplainAction; import org.elasticsearch.rest.action.search.RestMultiSearchAction; -import org.elasticsearch.rest.action.search.RestOpenReaderAction; +import org.elasticsearch.rest.action.search.RestOpenSearchContextAction; import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.rest.action.search.RestSearchScrollAction; import org.elasticsearch.tasks.Task; @@ -575,8 +572,8 @@ public void reg actions.register(MultiSearchAction.INSTANCE, TransportMultiSearchAction.class); actions.register(ExplainAction.INSTANCE, TransportExplainAction.class); actions.register(ClearScrollAction.INSTANCE, TransportClearScrollAction.class); - actions.register(TransportOpenReaderAction.INSTANCE, TransportOpenReaderAction.class); - actions.register(ClearReaderAction.INSTANCE, TransportClearReaderAction.class); + actions.register(TransportOpenSearchContextAction.INSTANCE, TransportOpenSearchContextAction.class); + actions.register(CloseSearchContextAction.INSTANCE, TransportCloseSearchContextAction.class); actions.register(RecoveryAction.INSTANCE, TransportRecoveryAction.class); actions.register(NodesReloadSecureSettingsAction.INSTANCE, TransportNodesReloadSecureSettingsAction.class); actions.register(AutoCreateAction.INSTANCE, AutoCreateAction.TransportAction.class); @@ -729,8 +726,8 @@ public void initRestHandlers(Supplier nodesInCluster) { registerHandler.accept(new RestSearchAction()); registerHandler.accept(new RestSearchScrollAction()); registerHandler.accept(new RestClearScrollAction()); - registerHandler.accept(new RestOpenReaderAction()); - registerHandler.accept(new RestClearReaderAction()); + registerHandler.accept(new RestOpenSearchContextAction()); + registerHandler.accept(new RestCloseSearchContextAction()); registerHandler.accept(new RestMultiSearchAction(settings)); registerHandler.accept(new RestValidateQueryAction()); diff --git a/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java b/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java index 77deb13df71cb..579ae8d362e23 100644 --- a/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java @@ -533,13 +533,13 @@ protected final SearchResponse buildSearchResponse(InternalSearchResponse intern ShardSearchFailure[] failures) { final Version minNodeVersion = clusterState.nodes().getMinNodeVersion(); String scrollId = request.scroll() != null ? TransportSearchHelper.buildScrollId(queryResults, minNodeVersion) : null; - String readerId = includeReaderIdInResponse() ? TransportSearchHelper.encodeReaderIds(queryResults, minNodeVersion) : null; + String readerId = includeSearchContextInResponse() ? TransportSearchHelper.encodeReaderIds(queryResults, minNodeVersion) : null; return new SearchResponse(internalSearchResponse, scrollId, getNumShards(), successfulOps.get(), skippedOps.get(), buildTookInMillis(), failures, clusters, readerId); } - boolean includeReaderIdInResponse() { - return request.reader() != null; + boolean includeSearchContextInResponse() { + return request.searchContextBuilder() != null; } @Override @@ -547,7 +547,7 @@ public void sendSearchResponse(InternalSearchResponse internalSearchResponse, At ShardSearchFailure[] failures = buildShardFailures(); Boolean allowPartialResults = request.allowPartialSearchResults(); assert allowPartialResults != null : "SearchRequest missing setting for allowPartialSearchResults"; - if (request.reader() == null && allowPartialResults == false && failures.length > 0) { + if (request.searchContextBuilder() == null && allowPartialResults == false && failures.length > 0) { raisePhaseFailure(new SearchPhaseExecutionException("", "Shard failures", null, failures)); } else { listener.onResponse(buildSearchResponse(internalSearchResponse, queryResults, failures)); diff --git a/server/src/main/java/org/elasticsearch/action/search/ClearContextController.java b/server/src/main/java/org/elasticsearch/action/search/ClearContextController.java index a9c0da94a8bc8..59a53eab6e50c 100644 --- a/server/src/main/java/org/elasticsearch/action/search/ClearContextController.java +++ b/server/src/main/java/org/elasticsearch/action/search/ClearContextController.java @@ -40,7 +40,7 @@ final class ClearContextController implements Runnable { private final DiscoveryNodes nodes; private final SearchTransportService searchTransportService; private final CountDown expectedOps; - private final ActionListener listener; + private final ActionListener listener; private final AtomicBoolean hasFailed = new AtomicBoolean(false); private final AtomicInteger freedSearchContexts = new AtomicInteger(0); private final Logger logger; @@ -68,14 +68,14 @@ final class ClearContextController implements Runnable { this.expectedOps = new CountDown(expectedOps); } - ClearContextController(ClearReaderRequest clearReaderRequest, ActionListener listener, + ClearContextController(CloseSearchContextRequest closeSearchContextRequest, ActionListener listener, DiscoveryNodes nodes, Logger logger, SearchTransportService searchTransportService) { this.nodes = nodes; this.logger = logger; this.searchTransportService = searchTransportService; this.listener = listener; final Collection contexts = - TransportSearchHelper.decodeReaderIds(clearReaderRequest.getId()).values(); + TransportSearchHelper.decodeReaderIds(closeSearchContextRequest.getId()).values(); expectedOps = new CountDown(contexts.size()); runner = () -> cleanReaderIds(contexts); } @@ -108,7 +108,7 @@ public void onFailure(Exception e) { void cleanReaderIds(Collection readerIds) { if (readerIds.isEmpty()) { - listener.onResponse(new ClearReaderResponse(true, 0)); + listener.onResponse(new CloseSearchContextResponse(true, 0)); return; } SearchScrollAsyncAction.collectNodesAndRun(readerIds, nodes, searchTransportService, ActionListener.wrap( @@ -136,7 +136,7 @@ private void onFreedContext(boolean freed) { } if (expectedOps.countDown()) { boolean succeeded = hasFailed.get() == false; - listener.onResponse(new ClearReaderResponse(succeeded, freedSearchContexts.get())); + listener.onResponse(new CloseSearchContextResponse(succeeded, freedSearchContexts.get())); } } @@ -148,7 +148,7 @@ private void onFailedFreedContext(Throwable e, DiscoveryNode node) { */ hasFailed.set(true); if (expectedOps.countDown()) { - listener.onResponse(new ClearReaderResponse(false, freedSearchContexts.get())); + listener.onResponse(new CloseSearchContextResponse(false, freedSearchContexts.get())); } } } diff --git a/server/src/main/java/org/elasticsearch/action/search/ClearReaderAction.java b/server/src/main/java/org/elasticsearch/action/search/CloseSearchContextAction.java similarity index 71% rename from server/src/main/java/org/elasticsearch/action/search/ClearReaderAction.java rename to server/src/main/java/org/elasticsearch/action/search/CloseSearchContextAction.java index d6215365e4aa9..3869d10019bbc 100644 --- a/server/src/main/java/org/elasticsearch/action/search/ClearReaderAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/CloseSearchContextAction.java @@ -21,12 +21,12 @@ import org.elasticsearch.action.ActionType; -public class ClearReaderAction extends ActionType { +public class CloseSearchContextAction extends ActionType { - public static final ClearReaderAction INSTANCE = new ClearReaderAction(); - public static final String NAME = "indices:data/read/reader/clear"; + public static final CloseSearchContextAction INSTANCE = new CloseSearchContextAction(); + public static final String NAME = "indices:data/read/close_search_context"; - private ClearReaderAction() { - super(NAME, ClearReaderResponse::new); + private CloseSearchContextAction() { + super(NAME, CloseSearchContextResponse::new); } } diff --git a/server/src/main/java/org/elasticsearch/action/search/ClearReaderRequest.java b/server/src/main/java/org/elasticsearch/action/search/CloseSearchContextRequest.java similarity index 87% rename from server/src/main/java/org/elasticsearch/action/search/ClearReaderRequest.java rename to server/src/main/java/org/elasticsearch/action/search/CloseSearchContextRequest.java index 75f85c3024d13..0d8a24f8a708d 100644 --- a/server/src/main/java/org/elasticsearch/action/search/ClearReaderRequest.java +++ b/server/src/main/java/org/elasticsearch/action/search/CloseSearchContextRequest.java @@ -31,17 +31,17 @@ import java.io.IOException; -public class ClearReaderRequest extends ActionRequest implements ToXContentObject { +public class CloseSearchContextRequest extends ActionRequest implements ToXContentObject { private static final ParseField ID = new ParseField("id"); private final String id; - public ClearReaderRequest(StreamInput in) throws IOException { + public CloseSearchContextRequest(StreamInput in) throws IOException { super(in); this.id = in.readString(); } - public ClearReaderRequest(String id) { + public CloseSearchContextRequest(String id) { this.id = id; } @@ -71,7 +71,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder; } - public static ClearReaderRequest fromXContent(XContentParser parser) throws IOException { + public static CloseSearchContextRequest fromXContent(XContentParser parser) throws IOException { if (parser.nextToken() != XContentParser.Token.START_OBJECT) { throw new IllegalArgumentException("Malformed content, must start with an object"); } else { @@ -90,9 +90,9 @@ public static ClearReaderRequest fromXContent(XContentParser parser) throws IOEx } } if (Strings.isNullOrEmpty(id)) { - throw new IllegalArgumentException("reader context is is not provided"); + throw new IllegalArgumentException("search context id is is not provided"); } - return new ClearReaderRequest(id); + return new CloseSearchContextRequest(id); } } } diff --git a/server/src/main/java/org/elasticsearch/action/search/ClearReaderResponse.java b/server/src/main/java/org/elasticsearch/action/search/CloseSearchContextResponse.java similarity index 81% rename from server/src/main/java/org/elasticsearch/action/search/ClearReaderResponse.java rename to server/src/main/java/org/elasticsearch/action/search/CloseSearchContextResponse.java index 6efdc11bdb0d2..a015c00331fd8 100644 --- a/server/src/main/java/org/elasticsearch/action/search/ClearReaderResponse.java +++ b/server/src/main/java/org/elasticsearch/action/search/CloseSearchContextResponse.java @@ -23,12 +23,12 @@ import java.io.IOException; -public class ClearReaderResponse extends ClearScrollResponse { - public ClearReaderResponse(boolean succeeded, int numFreed) { +public class CloseSearchContextResponse extends ClearScrollResponse { + public CloseSearchContextResponse(boolean succeeded, int numFreed) { super(succeeded, numFreed); } - public ClearReaderResponse(StreamInput in) throws IOException { + public CloseSearchContextResponse(StreamInput in) throws IOException { super(in); } } diff --git a/server/src/main/java/org/elasticsearch/action/search/FetchSearchPhase.java b/server/src/main/java/org/elasticsearch/action/search/FetchSearchPhase.java index a9c4587823862..2f1f2cee1ccc4 100644 --- a/server/src/main/java/org/elasticsearch/action/search/FetchSearchPhase.java +++ b/server/src/main/java/org/elasticsearch/action/search/FetchSearchPhase.java @@ -208,7 +208,9 @@ public void onFailure(Exception e) { private void releaseIrrelevantSearchContext(QuerySearchResult queryResult) { // we only release search context that we did not fetch from if we are not scrolling // and if it has at lease one hit that didn't make it to the global topDocs - if (context.getRequest().scroll() == null && context.getRequest().reader() == null && queryResult.hasSearchContext()) { + if (context.getRequest().scroll() == null && + context.getRequest().searchContextBuilder() == null && + queryResult.hasSearchContext()) { try { SearchShardTarget searchShardTarget = queryResult.getSearchShardTarget(); Transport.Connection connection = context.getConnection(searchShardTarget.getClusterAlias(), searchShardTarget.getNodeId()); diff --git a/server/src/main/java/org/elasticsearch/action/search/OpenReaderRequest.java b/server/src/main/java/org/elasticsearch/action/search/OpenSearchContextRequest.java similarity index 89% rename from server/src/main/java/org/elasticsearch/action/search/OpenReaderRequest.java rename to server/src/main/java/org/elasticsearch/action/search/OpenSearchContextRequest.java index c911b3124af66..5134568c8158a 100644 --- a/server/src/main/java/org/elasticsearch/action/search/OpenReaderRequest.java +++ b/server/src/main/java/org/elasticsearch/action/search/OpenSearchContextRequest.java @@ -36,7 +36,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; -public final class OpenReaderRequest extends ActionRequest implements IndicesRequest { +public final class OpenSearchContextRequest extends ActionRequest implements IndicesRequest { private final String[] indices; private final IndicesOptions indicesOptions; private final TimeValue keepAlive; @@ -48,7 +48,8 @@ public final class OpenReaderRequest extends ActionRequest implements IndicesReq public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.strictExpandOpenAndForbidClosed(); - public OpenReaderRequest(String[] indices, IndicesOptions indicesOptions, TimeValue keepAlive, String routing, String preference) { + public OpenSearchContextRequest(String[] indices, IndicesOptions indicesOptions, + TimeValue keepAlive, String routing, String preference) { this.indices = Objects.requireNonNull(indices); this.indicesOptions = Objects.requireNonNull(indicesOptions); this.keepAlive = keepAlive; @@ -56,7 +57,7 @@ public OpenReaderRequest(String[] indices, IndicesOptions indicesOptions, TimeVa this.preference = preference; } - public OpenReaderRequest(StreamInput in) throws IOException { + public OpenSearchContextRequest(StreamInput in) throws IOException { super(in); this.indices = in.readStringArray(); this.indicesOptions = IndicesOptions.readIndicesOptions(in); @@ -114,7 +115,7 @@ public Task createTask(long id, String type, String action, TaskId parentTaskId, return new SearchTask(id, type, action, null, parentTaskId, headers) { @Override public String getDescription() { - return "open reader: indices [" + String.join(",", indices) + "] keep_alive [" + keepAlive + "]"; + return "open search context: indices [" + String.join(",", indices) + "] keep_alive [" + keepAlive + "]"; } }; } diff --git a/server/src/main/java/org/elasticsearch/action/search/OpenReaderResponse.java b/server/src/main/java/org/elasticsearch/action/search/OpenSearchContextResponse.java similarity index 71% rename from server/src/main/java/org/elasticsearch/action/search/OpenReaderResponse.java rename to server/src/main/java/org/elasticsearch/action/search/OpenSearchContextResponse.java index 43114f7d14f19..7ce3061b4f858 100644 --- a/server/src/main/java/org/elasticsearch/action/search/OpenReaderResponse.java +++ b/server/src/main/java/org/elasticsearch/action/search/OpenSearchContextResponse.java @@ -28,34 +28,34 @@ import java.io.IOException; -public final class OpenReaderResponse extends ActionResponse implements ToXContentObject { - private static final ParseField READER_ID = new ParseField("reader_id"); +public final class OpenSearchContextResponse extends ActionResponse implements ToXContentObject { + private static final ParseField ID = new ParseField("id"); - private final String readerId; + private final String searchContextId; - public OpenReaderResponse(String readerId) { - this.readerId = readerId; + public OpenSearchContextResponse(String searchContextId) { + this.searchContextId = searchContextId; } - public OpenReaderResponse(StreamInput in) throws IOException { + public OpenSearchContextResponse(StreamInput in) throws IOException { super(in); - readerId = in.readString(); + searchContextId = in.readString(); } @Override public void writeTo(StreamOutput out) throws IOException { - out.writeString(readerId); + out.writeString(searchContextId); } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - builder.field(READER_ID.getPreferredName(), readerId); + builder.field(ID.getPreferredName(), searchContextId); builder.endObject(); return builder; } - public String getReaderId() { - return readerId; + public String getSearchContextId() { + return searchContextId; } } diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java b/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java index a6a2a47bbf31b..816d9efbf8a79 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchRequest.java @@ -277,7 +277,7 @@ public ActionRequestValidationException validate() { validationException = addValidationError("[request_cache] cannot be used in a scroll context", validationException); } - if (reader() != null) { + if (searchContextBuilder() != null) { validationException = addValidationError("using [reader] is not allowed in a scroll context", validationException); } } @@ -286,7 +286,7 @@ public ActionRequestValidationException validate() { validationException = source.aggregations().validate(validationException); } } - if (reader() != null) { + if (searchContextBuilder() != null) { if (indices.length > 0) { validationException = addValidationError("[index] cannot be used with reader contexts", validationException); } @@ -446,9 +446,9 @@ public SearchSourceBuilder source() { return source; } - public SearchSourceBuilder.ReaderBuilder reader() { + public SearchSourceBuilder.SearchContextBuilder searchContextBuilder() { if (source != null) { - return source.reader(); + return source.searchContextBuilder(); } return null; } diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java index 6a9f1e0c1e389..05f1cab42f902 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchRequestBuilder.java @@ -528,7 +528,7 @@ public SearchRequestBuilder setCollapse(CollapseBuilder collapse) { * @param keepAlive the extended keep alive for the readers used in this request */ public SearchRequestBuilder setReader(@Nullable String readerId, @Nullable TimeValue keepAlive) { - sourceBuilder().reader(new SearchSourceBuilder.ReaderBuilder(readerId, keepAlive)); + sourceBuilder().searchContextBuilder(new SearchSourceBuilder.SearchContextBuilder(readerId, keepAlive)); return this; } diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchResponse.java b/server/src/main/java/org/elasticsearch/action/search/SearchResponse.java index 8db0abf3fa574..482c846dbed55 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchResponse.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchResponse.java @@ -70,7 +70,7 @@ public class SearchResponse extends ActionResponse implements StatusToXContentOb private final SearchResponseSections internalResponse; private final String scrollId; - private final String readerId; + private final String searchContextId; private final int totalShards; private final int successfulShards; private final int skippedShards; @@ -97,17 +97,18 @@ public SearchResponse(StreamInput in) throws IOException { tookInMillis = in.readVLong(); skippedShards = in.readVInt(); if (in.getVersion().onOrAfter(Version.V_8_0_0)) { - readerId = in.readOptionalString(); + searchContextId = in.readOptionalString(); } else { - readerId = null; + searchContextId = null; } } public SearchResponse(SearchResponseSections internalResponse, String scrollId, int totalShards, int successfulShards, - int skippedShards, long tookInMillis, ShardSearchFailure[] shardFailures, Clusters clusters, String readerId) { + int skippedShards, long tookInMillis, ShardSearchFailure[] shardFailures, Clusters clusters, + String searchContextId) { this.internalResponse = internalResponse; this.scrollId = scrollId; - this.readerId = readerId; + this.searchContextId = searchContextId; this.clusters = clusters; this.totalShards = totalShards; this.successfulShards = successfulShards; @@ -115,8 +116,8 @@ public SearchResponse(SearchResponseSections internalResponse, String scrollId, this.tookInMillis = tookInMillis; this.shardFailures = shardFailures; assert skippedShards <= totalShards : "skipped: " + skippedShards + " total: " + totalShards; - assert scrollId == null || readerId == null : - "SearchResponse can't have both scrollId [" + scrollId + "] and readerId [" + readerId + "]"; + assert scrollId == null || searchContextId == null : + "SearchResponse can't have both scrollId [" + scrollId + "] and searchContextId [" + searchContextId + "]"; } @Override @@ -219,10 +220,10 @@ public String getScrollId() { } /** - * Returns the encoded string representing reader ids that ared used to executed the request. + * Returns the encoded string of the search context that the search request is used to executed */ - public String getReaderId() { - return readerId; + public String searchContextId() { + return searchContextId; } /** @@ -257,8 +258,8 @@ public XContentBuilder innerToXContent(XContentBuilder builder, Params params) t if (scrollId != null) { builder.field(SCROLL_ID.getPreferredName(), scrollId); } - if (readerId != null) { - builder.field(READER_ID.getPreferredName(), readerId); + if (searchContextId != null) { + builder.field(READER_ID.getPreferredName(), searchContextId); } builder.field(TOOK.getPreferredName(), tookInMillis); builder.field(TIMED_OUT.getPreferredName(), isTimedOut()); @@ -403,7 +404,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeVLong(tookInMillis); out.writeVInt(skippedShards); if (out.getVersion().onOrAfter(Version.V_8_0_0)) { - out.writeOptionalString(readerId); + out.writeOptionalString(searchContextId); } } diff --git a/server/src/main/java/org/elasticsearch/action/search/SearchTransportService.java b/server/src/main/java/org/elasticsearch/action/search/SearchTransportService.java index 38a0288c5e2f0..7156e6ee840c3 100644 --- a/server/src/main/java/org/elasticsearch/action/search/SearchTransportService.java +++ b/server/src/main/java/org/elasticsearch/action/search/SearchTransportService.java @@ -170,10 +170,10 @@ public void sendExecuteFetchScroll(Transport.Connection connection, final ShardF } void sendShardOpenReader(Transport.Connection connection, SearchTask task, - TransportOpenReaderAction.ShardOpenReaderRequest request, - ActionListener listener) { + TransportOpenSearchContextAction.ShardOpenReaderRequest request, + ActionListener listener) { transportService.sendChildRequest(connection, SHARD_OPEN_READER_NAME, request, task, - new ActionListenerResponseHandler<>(listener, TransportOpenReaderAction.ShardOpenReaderResponse::new)); + new ActionListenerResponseHandler<>(listener, TransportOpenSearchContextAction.ShardOpenReaderResponse::new)); } private void sendExecuteFetch(Transport.Connection connection, String action, final ShardFetchRequest request, SearchTask task, @@ -372,14 +372,14 @@ public static void registerRequestHandler(TransportService transportService, Sea TransportActionProxy.registerProxyAction(transportService, QUERY_CAN_MATCH_NAME, SearchService.CanMatchResponse::new); transportService.registerRequestHandler(SHARD_OPEN_READER_NAME, ThreadPool.Names.SAME, - TransportOpenReaderAction.ShardOpenReaderRequest::new, + TransportOpenSearchContextAction.ShardOpenReaderRequest::new, (request, channel, task) -> { searchService.openReaderContext(request.getShardId(), request.keepAlive, ActionListener.map(new ChannelActionListener<>(channel, SHARD_OPEN_READER_NAME, request), - contextId -> new TransportOpenReaderAction.ShardOpenReaderResponse(contextId))); + contextId -> new TransportOpenSearchContextAction.ShardOpenReaderResponse(contextId))); }); TransportActionProxy.registerProxyAction( - transportService, SHARD_OPEN_READER_NAME, TransportOpenReaderAction.ShardOpenReaderResponse::new); + transportService, SHARD_OPEN_READER_NAME, TransportOpenSearchContextAction.ShardOpenReaderResponse::new); } diff --git a/server/src/main/java/org/elasticsearch/action/search/TransportClearReaderAction.java b/server/src/main/java/org/elasticsearch/action/search/TransportCloseSearchContextAction.java similarity index 72% rename from server/src/main/java/org/elasticsearch/action/search/TransportClearReaderAction.java rename to server/src/main/java/org/elasticsearch/action/search/TransportCloseSearchContextAction.java index eb0e586a1c774..23311624961bf 100644 --- a/server/src/main/java/org/elasticsearch/action/search/TransportClearReaderAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/TransportCloseSearchContextAction.java @@ -27,21 +27,21 @@ import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; -public class TransportClearReaderAction extends HandledTransportAction { +public class TransportCloseSearchContextAction extends HandledTransportAction { private final ClusterService clusterService; private final SearchTransportService searchTransportService; @Inject - public TransportClearReaderAction(TransportService transportService, ClusterService clusterService, - ActionFilters actionFilters, SearchTransportService searchTransportService) { - super(ClearReaderAction.NAME, transportService, actionFilters, ClearReaderRequest::new); + public TransportCloseSearchContextAction(TransportService transportService, ClusterService clusterService, + ActionFilters actionFilters, SearchTransportService searchTransportService) { + super(CloseSearchContextAction.NAME, transportService, actionFilters, CloseSearchContextRequest::new); this.clusterService = clusterService; this.searchTransportService = searchTransportService; } @Override - protected void doExecute(Task task, ClearReaderRequest request, ActionListener listener) { + protected void doExecute(Task task, CloseSearchContextRequest request, ActionListener listener) { Runnable runnable = new ClearContextController( request, listener, clusterService.state().nodes(), logger, searchTransportService); runnable.run(); diff --git a/server/src/main/java/org/elasticsearch/action/search/TransportOpenReaderAction.java b/server/src/main/java/org/elasticsearch/action/search/TransportOpenSearchContextAction.java similarity index 81% rename from server/src/main/java/org/elasticsearch/action/search/TransportOpenReaderAction.java rename to server/src/main/java/org/elasticsearch/action/search/TransportOpenSearchContextAction.java index b827610893617..bc004968e0213 100644 --- a/server/src/main/java/org/elasticsearch/action/search/TransportOpenReaderAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/TransportOpenSearchContextAction.java @@ -53,23 +53,23 @@ import java.util.concurrent.Executor; import java.util.function.BiFunction; -public class TransportOpenReaderAction extends HandledTransportAction { - public static final String NAME = "indices:data/read/open_reader"; - public static final ActionType INSTANCE = new ActionType<>(NAME, OpenReaderResponse::new); +public class TransportOpenSearchContextAction extends HandledTransportAction { + public static final String NAME = "indices:data/read/open_search_context"; + public static final ActionType INSTANCE = new ActionType<>(NAME, OpenSearchContextResponse::new); private final TransportSearchAction transportSearchAction; private final SearchTransportService searchTransportService; @Inject - public TransportOpenReaderAction(TransportService transportService, SearchTransportService searchTransportService, - ActionFilters actionFilters, TransportSearchAction transportSearchAction) { - super(NAME, transportService, actionFilters, OpenReaderRequest::new); + public TransportOpenSearchContextAction(TransportService transportService, SearchTransportService searchTransportService, + ActionFilters actionFilters, TransportSearchAction transportSearchAction) { + super(NAME, transportService, actionFilters, OpenSearchContextRequest::new); this.transportSearchAction = transportSearchAction; this.searchTransportService = searchTransportService; } @Override - protected void doExecute(Task task, OpenReaderRequest openReaderRequest, ActionListener listener) { + protected void doExecute(Task task, OpenSearchContextRequest request, ActionListener listener) { final TransportSearchAction.SearchAsyncActionProvider actionProvider = new TransportSearchAction.SearchAsyncActionProvider() { @Override public AbstractSearchAsyncAction asyncSearchAction( @@ -79,19 +79,19 @@ public AbstractSearchAsyncAction asyncSearchAction( Map> indexRoutings, ActionListener listener, boolean preFilter, ThreadPool threadPool, SearchResponse.Clusters clusters) { final Executor executor = threadPool.executor(ThreadPool.Names.SEARCH); - return new OpenReaderSearchPhase(openReaderRequest, logger, searchTransportService, connectionLookup, + return new OpenReaderSearchPhase(request, logger, searchTransportService, connectionLookup, aliasFilter, concreteIndexBoosts, indexRoutings, executor, searchRequest, listener, shardIterators, timeProvider, clusterState, task, clusters); } }; final SearchRequest searchRequest = new SearchRequest() - .indices(openReaderRequest.indices()) - .indicesOptions(openReaderRequest.indicesOptions()) - .preference(openReaderRequest.preference()) - .routing(openReaderRequest.routing()) + .indices(request.indices()) + .indicesOptions(request.indicesOptions()) + .preference(request.preference()) + .routing(request.routing()) .allowPartialSearchResults(false); transportSearchAction.executeRequest(task, searchRequest, actionProvider, - ActionListener.map(listener, r -> new OpenReaderResponse(r.getReaderId()))); + ActionListener.map(listener, r -> new OpenSearchContextResponse(r.searchContextId()))); } static final class ShardOpenReaderRequest extends TransportRequest implements IndicesRequest { @@ -152,19 +152,19 @@ public void writeTo(StreamOutput out) throws IOException { } static final class OpenReaderSearchPhase extends AbstractSearchAsyncAction { - final OpenReaderRequest openReaderRequest; + final OpenSearchContextRequest request; - OpenReaderSearchPhase(OpenReaderRequest openReaderRequest, Logger logger, SearchTransportService searchTransportService, + OpenReaderSearchPhase(OpenSearchContextRequest request, Logger logger, SearchTransportService searchTransportService, BiFunction nodeIdToConnection, Map aliasFilter, Map concreteIndexBoosts, - Map> indexRoutings, Executor executor, SearchRequest request, + Map> indexRoutings, Executor executor, SearchRequest searchRequest, ActionListener listener, GroupShardsIterator shardsIts, TransportSearchAction.SearchTimeProvider timeProvider, ClusterState clusterState, SearchTask task, SearchResponse.Clusters clusters) { - super("open_reader", logger, searchTransportService, nodeIdToConnection, aliasFilter, concreteIndexBoosts, indexRoutings, - executor, request, listener, shardsIts, timeProvider, clusterState, task, + super("open_search_context", logger, searchTransportService, nodeIdToConnection, aliasFilter, concreteIndexBoosts, + indexRoutings, executor, searchRequest, listener, shardsIts, timeProvider, clusterState, task, new ArraySearchPhaseResults<>(shardsIts.size()), shardsIts.size(), clusters); - this.openReaderRequest = openReaderRequest; + this.request = request; } @Override @@ -173,7 +173,7 @@ protected void executePhaseOnShard(SearchShardIterator shardIt, ShardRouting sha final Transport.Connection connection = getConnection(shardIt.getClusterAlias(), shard.currentNodeId()); final SearchShardTarget searchShardTarget = shardIt.newSearchShardTarget(shard.currentNodeId()); final ShardOpenReaderRequest shardRequest = new ShardOpenReaderRequest(searchShardTarget.getShardId(), - searchShardTarget.getOriginalIndices(), openReaderRequest.keepAlive()); + searchShardTarget.getOriginalIndices(), request.keepAlive()); getSearchTransport().sendShardOpenReader(connection, getTask(), shardRequest, ActionListener.map(listener, r -> r)); } @@ -189,7 +189,7 @@ public void run() { } @Override - boolean includeReaderIdInResponse() { + boolean includeSearchContextInResponse() { return true; } } diff --git a/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java b/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java index edb0f361c6afc..9d683131d311f 100644 --- a/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java +++ b/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java @@ -216,8 +216,8 @@ void executeRequest(Task task, SearchRequest searchRequest, } final Map readerContexts; final Map remoteClusterIndices; - if (searchRequest.reader() != null) { - readerContexts = TransportSearchHelper.decodeReaderIds(searchRequest.reader().getId()); + if (searchRequest.searchContextBuilder() != null) { + readerContexts = TransportSearchHelper.decodeReaderIds(searchRequest.searchContextBuilder().getId()); remoteClusterIndices = indicesFromReaderContexts(readerContexts, searchRequest.indicesOptions()); } else { readerContexts = null; @@ -272,7 +272,7 @@ static boolean shouldMinimizeRoundtrips(SearchRequest searchRequest) { if (searchRequest.scroll() != null) { return false; } - if (searchRequest.reader() != null) { + if (searchRequest.searchContextBuilder() != null) { // TODO: support reader contexts return false; } @@ -311,7 +311,7 @@ public void onResponse(SearchResponse searchResponse) { listener.onResponse(new SearchResponse(internalSearchResponse, searchResponse.getScrollId(), searchResponse.getTotalShards(), searchResponse.getSuccessfulShards(), searchResponse.getSkippedShards(), timeProvider.buildTookInMillis(), searchResponse.getShardFailures(), new SearchResponse.Clusters(1, 1, 0), - searchResponse.getReaderId())); + searchResponse.searchContextId())); } @Override @@ -509,14 +509,14 @@ private void executeSearch(SearchTask task, SearchTimeProvider timeProvider, Sea boolean preFilterSearchShards; if (readerContexts != null) { - assert searchRequest.reader() != null; + assert searchRequest.searchContextBuilder() != null; aliasFilter = new HashMap<>(); for (ShardId shardId : readerContexts.keySet()) { aliasFilter.put(shardId.getIndex().getUUID(), AliasFilter.EMPTY); } indexRoutings = Map.of(); - localShardIterators = searchShardsFromReaderContexts( - clusterState, localIndices, searchRequest.getLocalClusterAlias(), readerContexts, searchRequest.reader().getKeepAlive()); + localShardIterators = searchShardsFromReaderContexts(clusterState, localIndices, searchRequest.getLocalClusterAlias(), + readerContexts, searchRequest.searchContextBuilder().getKeepAlive()); preFilterSearchShards = shouldPreFilterSearchShards(clusterState, searchRequest, localIndices.indices(), localShardIterators.size() + remoteShardIterators.size()); } else { diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestClearReaderAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestCloseSearchContextAction.java similarity index 73% rename from server/src/main/java/org/elasticsearch/rest/action/search/RestClearReaderAction.java rename to server/src/main/java/org/elasticsearch/rest/action/search/RestCloseSearchContextAction.java index c672ad821778f..6a76559789fae 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestClearReaderAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestCloseSearchContextAction.java @@ -19,8 +19,8 @@ package org.elasticsearch.rest.action.search; -import org.elasticsearch.action.search.ClearReaderAction; -import org.elasticsearch.action.search.ClearReaderRequest; +import org.elasticsearch.action.search.CloseSearchContextAction; +import org.elasticsearch.action.search.CloseSearchContextRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; @@ -32,24 +32,24 @@ import static org.elasticsearch.rest.RestRequest.Method.DELETE; -public class RestClearReaderAction extends BaseRestHandler { +public class RestCloseSearchContextAction extends BaseRestHandler { @Override public List routes() { - return List.of(new Route(DELETE, "/_search/reader")); + return List.of(new Route(DELETE, "/_search_context")); } @Override public String getName() { - return "clear_reader_action"; + return "close_search_context"; } @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { - final ClearReaderRequest clearRequest; + final CloseSearchContextRequest clearRequest; try (XContentParser parser = request.contentOrSourceParamParser()) { - clearRequest = ClearReaderRequest.fromXContent(parser); + clearRequest = CloseSearchContextRequest.fromXContent(parser); } - return channel -> client.execute(ClearReaderAction.INSTANCE, clearRequest, new RestStatusToXContentListener<>(channel)); + return channel -> client.execute(CloseSearchContextAction.INSTANCE, clearRequest, new RestStatusToXContentListener<>(channel)); } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestOpenReaderAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestOpenSearchContextAction.java similarity index 74% rename from server/src/main/java/org/elasticsearch/rest/action/search/RestOpenReaderAction.java rename to server/src/main/java/org/elasticsearch/rest/action/search/RestOpenSearchContextAction.java index 7294347fc1e1e..e992efe8eb639 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestOpenReaderAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestOpenSearchContextAction.java @@ -19,8 +19,8 @@ package org.elasticsearch.rest.action.search; -import org.elasticsearch.action.search.OpenReaderRequest; -import org.elasticsearch.action.search.TransportOpenReaderAction; +import org.elasticsearch.action.search.OpenSearchContextRequest; +import org.elasticsearch.action.search.TransportOpenSearchContextAction; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; @@ -34,26 +34,26 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; -public class RestOpenReaderAction extends BaseRestHandler { +public class RestOpenSearchContextAction extends BaseRestHandler { @Override public String getName() { - return "open_reader_action"; + return "open_search_context"; } @Override public List routes() { - return List.of(new Route(POST, "/{index}/_open_reader")); + return List.of(new Route(POST, "/{index}/_search_context")); } @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final String[] indices = Strings.splitStringByCommaToArray(request.param("index")); - final IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, OpenReaderRequest.DEFAULT_INDICES_OPTIONS); + final IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, OpenSearchContextRequest.DEFAULT_INDICES_OPTIONS); final String routing = request.param("routing"); final String preference = request.param("preference"); final TimeValue keepAlive = TimeValue.parseTimeValue(request.param("keep_alive"), null, "keep_alive"); - final OpenReaderRequest openReaderRequest = new OpenReaderRequest(indices, indicesOptions, keepAlive, routing, preference); - return channel -> client.execute(TransportOpenReaderAction.INSTANCE, openReaderRequest, new RestToXContentListener<>(channel)); + final OpenSearchContextRequest openRequest = new OpenSearchContextRequest(indices, indicesOptions, keepAlive, routing, preference); + return channel -> client.execute(TransportOpenSearchContextAction.INSTANCE, openRequest, new RestToXContentListener<>(channel)); } } diff --git a/server/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/server/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index 1b20917e785f3..4fa78400cc1bc 100644 --- a/server/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -114,7 +114,7 @@ public final class SearchSourceBuilder implements Writeable, ToXContentObject, R public static final ParseField SEARCH_AFTER = new ParseField("search_after"); public static final ParseField COLLAPSE = new ParseField("collapse"); public static final ParseField SLICE = new ParseField("slice"); - public static final ParseField READER_CONTEXT = new ParseField("reader"); + public static final ParseField SEARCH_CONTEXT = new ParseField("search_context"); public static SearchSourceBuilder fromXContent(XContentParser parser) throws IOException { return fromXContent(parser, true); @@ -193,7 +193,7 @@ public static HighlightBuilder highlight() { private CollapseBuilder collapse = null; - private ReaderBuilder reader = null; + private SearchContextBuilder searchContextBuilder = null; /** * Constructs a new search source builder. @@ -250,7 +250,7 @@ public SearchSourceBuilder(StreamInput in) throws IOException { collapse = in.readOptionalWriteable(CollapseBuilder::new); trackTotalHitsUpTo = in.readOptionalInt(); if (in.getVersion().onOrAfter(Version.V_8_0_0)) { - reader = in.readOptionalWriteable(ReaderBuilder::new); + searchContextBuilder = in.readOptionalWriteable(SearchContextBuilder::new); } } @@ -307,7 +307,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeOptionalWriteable(collapse); out.writeOptionalInt(trackTotalHitsUpTo); if (out.getVersion().onOrAfter(Version.V_8_0_0)) { - out.writeOptionalWriteable(reader); + out.writeOptionalWriteable(searchContextBuilder); } } @@ -928,17 +928,17 @@ public boolean isSuggestOnly() { } /** - * Returns the reader context that is configured with this query + * Returns the search context that is configured with this query */ - public ReaderBuilder reader() { - return reader; + public SearchContextBuilder searchContextBuilder() { + return searchContextBuilder; } /** - * Specify the reader context that this query should use to execute. + * Specify a search context that this query should execute against. */ - public SearchSourceBuilder reader(ReaderBuilder reader) { - this.reader = reader; + public SearchSourceBuilder searchContextBuilder(SearchContextBuilder reader) { + this.searchContextBuilder = reader; return this; } @@ -1026,7 +1026,7 @@ private SearchSourceBuilder shallowCopy(QueryBuilder queryBuilder, QueryBuilder rewrittenBuilder.version = version; rewrittenBuilder.seqNoAndPrimaryTerm = seqNoAndPrimaryTerm; rewrittenBuilder.collapse = collapse; - rewrittenBuilder.reader = reader; + rewrittenBuilder.searchContextBuilder = searchContextBuilder; return rewrittenBuilder; } @@ -1135,8 +1135,9 @@ public void parseXContent(XContentParser parser, boolean checkTrailingTokens) th sliceBuilder = SliceBuilder.fromXContent(parser); } else if (COLLAPSE.match(currentFieldName, parser.getDeprecationHandler())) { collapse = CollapseBuilder.fromXContent(parser); - } else if (READER_CONTEXT.match(currentFieldName, parser.getDeprecationHandler())) { - reader = ReaderBuilder.fromXContent(parser); + } else if (SEARCH_CONTEXT.match(currentFieldName, parser.getDeprecationHandler())) { + searchContextBuilder = SearchContextBuilder. + fromXContent(parser); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); @@ -1333,8 +1334,8 @@ public XContentBuilder innerToXContent(XContentBuilder builder, Params params) t if (collapse != null) { builder.field(COLLAPSE.getPreferredName(), collapse); } - if (reader != null) { - builder.field(READER_CONTEXT.getPreferredName(), reader); + if (searchContextBuilder != null) { + builder.field(SEARCH_CONTEXT.getPreferredName(), searchContextBuilder); } return builder; } @@ -1548,7 +1549,7 @@ public int hashCode() { return Objects.hash(aggregations, explain, fetchSourceContext, docValueFields, storedFieldsContext, from, highlightBuilder, indexBoosts, minScore, postQueryBuilder, queryBuilder, rescoreBuilders, scriptFields, size, sorts, searchAfterBuilder, sliceBuilder, stats, suggestBuilder, terminateAfter, timeout, trackScores, version, - seqNoAndPrimaryTerm, profile, extBuilders, collapse, trackTotalHitsUpTo, reader); + seqNoAndPrimaryTerm, profile, extBuilders, collapse, trackTotalHitsUpTo, searchContextBuilder); } @Override @@ -1588,7 +1589,7 @@ public boolean equals(Object obj) { && Objects.equals(extBuilders, other.extBuilders) && Objects.equals(collapse, other.collapse) && Objects.equals(trackTotalHitsUpTo, other.trackTotalHitsUpTo) - && Objects.equals(reader, other.reader); + && Objects.equals(searchContextBuilder, other.searchContextBuilder); } @Override @@ -1607,13 +1608,13 @@ public String toString(Params params) { /** * Specify whether this search should use specific reader contexts instead of the latest ones. */ - public static final class ReaderBuilder implements Writeable, ToXContentObject { + public static final class SearchContextBuilder implements Writeable, ToXContentObject { private static final ParseField ID_FIELD = new ParseField("id"); private static final ParseField KEEP_ALIVE_FIELD = new ParseField("keep_alive"); private static final ObjectParser PARSER; static { - PARSER = new ObjectParser<>(READER_CONTEXT.getPreferredName(), XContentParams::new); + PARSER = new ObjectParser<>(SEARCH_CONTEXT.getPreferredName(), XContentParams::new); PARSER.declareString((params, id) -> params.id = id, ID_FIELD); PARSER.declareField((params, keepAlive) -> params.keepAlive = keepAlive, (p, c) -> TimeValue.parseTimeValue(p.text(), KEEP_ALIVE_FIELD.getPreferredName()), @@ -1628,12 +1629,12 @@ private static final class XContentParams { private final String id; private final TimeValue keepAlive; - public ReaderBuilder(String id, TimeValue keepAlive) { + public SearchContextBuilder(String id, TimeValue keepAlive) { this.id = Objects.requireNonNull(id); this.keepAlive = Objects.requireNonNull(keepAlive); } - public ReaderBuilder(StreamInput in) throws IOException { + public SearchContextBuilder(StreamInput in) throws IOException { id = in.readString(); keepAlive = in.readTimeValue(); } @@ -1651,12 +1652,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder; } - public static ReaderBuilder fromXContent(XContentParser parser) throws IOException { + public static SearchContextBuilder fromXContent(XContentParser parser) throws IOException { final XContentParams params = PARSER.parse(parser, null); if (params.id == null || params.keepAlive == null) { throw new IllegalArgumentException("id and keep_alive must be specified"); } - return new ReaderBuilder(params.id, params.keepAlive); + return new SearchContextBuilder(params.id, params.keepAlive); } public TimeValue getKeepAlive() { @@ -1671,7 +1672,7 @@ public String getId() { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - final ReaderBuilder that = (ReaderBuilder) o; + final SearchContextBuilder that = (SearchContextBuilder) o; return Objects.equals(id, that.id) && Objects.equals(keepAlive, that.keepAlive); } diff --git a/server/src/test/java/org/elasticsearch/action/search/MockSearchPhaseContext.java b/server/src/test/java/org/elasticsearch/action/search/MockSearchPhaseContext.java index 21b6363c8015d..b0ddabe498153 100644 --- a/server/src/test/java/org/elasticsearch/action/search/MockSearchPhaseContext.java +++ b/server/src/test/java/org/elasticsearch/action/search/MockSearchPhaseContext.java @@ -88,9 +88,10 @@ public SearchRequest getRequest() { @Override public void sendSearchResponse(InternalSearchResponse internalSearchResponse, AtomicArray queryResults) { String scrollId = getRequest().scroll() != null ? TransportSearchHelper.buildScrollId(queryResults, Version.CURRENT) : null; - String readerContextId = getRequest().reader() != null ? TransportSearchHelper.buildScrollId(queryResults, Version.CURRENT) : null; + String searchContextId = + getRequest().searchContextBuilder() != null ? TransportSearchHelper.buildScrollId(queryResults, Version.CURRENT) : null; searchResponse.set(new SearchResponse(internalSearchResponse, scrollId, numShards, numSuccess.get(), 0, 0, - failures.toArray(ShardSearchFailure.EMPTY_ARRAY), SearchResponse.Clusters.EMPTY, readerContextId)); + failures.toArray(ShardSearchFailure.EMPTY_ARRAY), SearchResponse.Clusters.EMPTY, searchContextId)); } @Override diff --git a/server/src/test/java/org/elasticsearch/action/search/SearchRequestTests.java b/server/src/test/java/org/elasticsearch/action/search/SearchRequestTests.java index 6f99c7c981fa7..e6e5f2af93f20 100644 --- a/server/src/test/java/org/elasticsearch/action/search/SearchRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/SearchRequestTests.java @@ -167,8 +167,8 @@ public void testValidate() throws IOException { { // Reader context with scroll SearchRequest searchRequest = new SearchRequest() - .source(new SearchSourceBuilder() - .reader(new SearchSourceBuilder.ReaderBuilder("id", TimeValue.timeValueMillis(randomIntBetween(1, 10))))) + .source(new SearchSourceBuilder().searchContextBuilder( + new SearchSourceBuilder.SearchContextBuilder("id", TimeValue.timeValueMillis(randomIntBetween(1, 10))))) .scroll(TimeValue.timeValueMillis(randomIntBetween(1, 100))); ActionRequestValidationException validationErrors = searchRequest.validate(); assertNotNull(validationErrors); @@ -179,7 +179,7 @@ public void testValidate() throws IOException { // Reader context with indices SearchRequest searchRequest = new SearchRequest() .source(new SearchSourceBuilder() - .reader(new SearchSourceBuilder.ReaderBuilder("id", TimeValue.timeValueMillis(randomIntBetween(1, 10))))) + .searchContextBuilder(new SearchSourceBuilder.SearchContextBuilder("id", TimeValue.timeValueMillis(between(1, 10))))) .indices("test"); ActionRequestValidationException validationErrors = searchRequest.validate(); assertNotNull(validationErrors); @@ -189,8 +189,8 @@ public void testValidate() throws IOException { { // Reader context with preference SearchRequest searchRequest = new SearchRequest() - .source(new SearchSourceBuilder() - .reader(new SearchSourceBuilder.ReaderBuilder("id", TimeValue.timeValueMillis(randomIntBetween(1, 10))))) + .source(new SearchSourceBuilder(). + searchContextBuilder(new SearchSourceBuilder.SearchContextBuilder("id", TimeValue.timeValueMillis(between(1, 10))))) .preference("test"); ActionRequestValidationException validationErrors = searchRequest.validate(); assertNotNull(validationErrors); @@ -201,7 +201,7 @@ public void testValidate() throws IOException { // Reader context with routing SearchRequest searchRequest = new SearchRequest() .source(new SearchSourceBuilder() - .reader(new SearchSourceBuilder.ReaderBuilder("id", TimeValue.timeValueMillis(randomIntBetween(1, 10))))) + .searchContextBuilder(new SearchSourceBuilder.SearchContextBuilder("id", TimeValue.timeValueMillis(between(1, 10))))) .routing("test"); ActionRequestValidationException validationErrors = searchRequest.validate(); assertNotNull(validationErrors); diff --git a/x-pack/plugin/frozen-indices/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java b/x-pack/plugin/frozen-indices/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java index dd6d22342990c..bf86bb90631fb 100644 --- a/x-pack/plugin/frozen-indices/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java +++ b/x-pack/plugin/frozen-indices/src/test/java/org/elasticsearch/index/engine/FrozenIndexTests.java @@ -11,14 +11,14 @@ import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; import org.elasticsearch.action.delete.DeleteResponse; import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.action.search.ClearReaderAction; -import org.elasticsearch.action.search.ClearReaderRequest; -import org.elasticsearch.action.search.OpenReaderRequest; -import org.elasticsearch.action.search.OpenReaderResponse; +import org.elasticsearch.action.search.CloseSearchContextAction; +import org.elasticsearch.action.search.CloseSearchContextRequest; +import org.elasticsearch.action.search.OpenSearchContextRequest; +import org.elasticsearch.action.search.OpenSearchContextResponse; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.action.search.TransportOpenReaderAction; +import org.elasticsearch.action.search.TransportOpenSearchContextAction; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.metadata.IndexMetadata; @@ -71,11 +71,11 @@ protected Collection> getPlugins() { } String openReaders(TimeValue keepAlive, String... indices) { - OpenReaderRequest request = new OpenReaderRequest(indices, IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED, + OpenSearchContextRequest request = new OpenSearchContextRequest(indices, IndicesOptions.STRICT_EXPAND_OPEN_FORBID_CLOSED, keepAlive, null, null); - final OpenReaderResponse response = client() - .execute(TransportOpenReaderAction.INSTANCE, request).actionGet(); - return response.getReaderId(); + final OpenSearchContextResponse response = client() + .execute(TransportOpenSearchContextAction.INSTANCE, request).actionGet(); + return response.getSearchContextId(); } public void testCloseFreezeAndOpen() throws Exception { @@ -139,7 +139,7 @@ public void testCloseFreezeAndOpen() throws Exception { } } } finally { - client().execute(ClearReaderAction.INSTANCE, new ClearReaderRequest(searchResponse.getReaderId())).get(); + client().execute(CloseSearchContextAction.INSTANCE, new CloseSearchContextRequest(searchResponse.searchContextId())).get(); } } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/RBACEngine.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/RBACEngine.java index 3cfb060d20808..e105b23b401b0 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/RBACEngine.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/RBACEngine.java @@ -20,7 +20,7 @@ import org.elasticsearch.action.delete.DeleteAction; import org.elasticsearch.action.get.MultiGetAction; import org.elasticsearch.action.index.IndexAction; -import org.elasticsearch.action.search.ClearReaderAction; +import org.elasticsearch.action.search.CloseSearchContextAction; import org.elasticsearch.action.search.ClearScrollAction; import org.elasticsearch.action.search.MultiSearchAction; import org.elasticsearch.action.search.SearchScrollAction; @@ -278,7 +278,7 @@ public void authorizeIndexAction(RequestInfo requestInfo, AuthorizationInfo auth // the same as the user that submitted the original request so we can skip security here. listener.onResponse(new IndexAuthorizationResult(true, IndicesAccessControl.ALLOW_NO_INDICES)); } - } else if (action.equals(ClearReaderAction.NAME)) { + } else if (action.equals(CloseSearchContextAction.NAME)) { // NORELEASE: ensure security works correctly listener.onResponse(new IndexAuthorizationResult(true, IndicesAccessControl.ALLOW_NO_INDICES)); } else { diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java index 87b25c5cf3f50..9389deccb792a 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentLevelSecurityTests.java @@ -12,8 +12,8 @@ import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.MultiGetResponse; -import org.elasticsearch.action.search.ClearReaderAction; -import org.elasticsearch.action.search.ClearReaderRequest; +import org.elasticsearch.action.search.CloseSearchContextAction; +import org.elasticsearch.action.search.CloseSearchContextRequest; import org.elasticsearch.action.search.MultiSearchResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.termvectors.MultiTermVectorsResponse; @@ -65,7 +65,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery; -import static org.elasticsearch.integration.FieldLevelSecurityTests.openReaders; +import static org.elasticsearch.integration.FieldLevelSecurityTests.openSearchContext; import static org.elasticsearch.join.query.JoinQueryBuilders.hasChildQuery; import static org.elasticsearch.join.query.JoinQueryBuilders.hasParentQuery; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -780,7 +780,7 @@ public void testReaderId() throws Exception { } refresh(); - String readerId = openReaders("user1", TimeValue.timeValueMinutes(1), "test"); + String readerId = openSearchContext("user1", TimeValue.timeValueMinutes(1), "test"); SearchResponse response = null; try { for (int from = 0; from < numVisible; from++) { @@ -798,7 +798,7 @@ public void testReaderId() throws Exception { assertThat(response.getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); } } finally { - client().execute(ClearReaderAction.INSTANCE, new ClearReaderRequest(response.getReaderId())).actionGet(); + client().execute(CloseSearchContextAction.INSTANCE, new CloseSearchContextRequest(response.searchContextId())).actionGet(); } } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java index f7b1e227cdd3b..17754ae429432 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/FieldLevelSecurityTests.java @@ -11,13 +11,13 @@ import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.get.MultiGetResponse; -import org.elasticsearch.action.search.ClearReaderAction; -import org.elasticsearch.action.search.ClearReaderRequest; +import org.elasticsearch.action.search.CloseSearchContextAction; +import org.elasticsearch.action.search.CloseSearchContextRequest; import org.elasticsearch.action.search.MultiSearchResponse; -import org.elasticsearch.action.search.OpenReaderRequest; -import org.elasticsearch.action.search.OpenReaderResponse; +import org.elasticsearch.action.search.OpenSearchContextRequest; +import org.elasticsearch.action.search.OpenSearchContextResponse; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.TransportOpenReaderAction; +import org.elasticsearch.action.search.TransportOpenSearchContextAction; import org.elasticsearch.action.termvectors.MultiTermVectorsResponse; import org.elasticsearch.action.termvectors.TermVectorsRequest; import org.elasticsearch.action.termvectors.TermVectorsResponse; @@ -728,12 +728,13 @@ public void testScroll() throws Exception { } } - static String openReaders(String userName, TimeValue keepAlive, String... indices) { - OpenReaderRequest request = new OpenReaderRequest(indices, OpenReaderRequest.DEFAULT_INDICES_OPTIONS, keepAlive, null, null); - final OpenReaderResponse response = client() + static String openSearchContext(String userName, TimeValue keepAlive, String... indices) { + OpenSearchContextRequest request = new OpenSearchContextRequest( + indices, OpenSearchContextRequest.DEFAULT_INDICES_OPTIONS, keepAlive, null, null); + final OpenSearchContextResponse response = client() .filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue(userName, USERS_PASSWD))) - .execute(TransportOpenReaderAction.INSTANCE, request).actionGet(); - return response.getReaderId(); + .execute(TransportOpenSearchContextAction.INSTANCE, request).actionGet(); + return response.getSearchContextId(); } public void testReaderId() throws Exception { @@ -750,7 +751,7 @@ public void testReaderId() throws Exception { } refresh("test"); - String readerId = openReaders("user1", TimeValue.timeValueMinutes(1), "test"); + String readerId = openSearchContext("user1", TimeValue.timeValueMinutes(1), "test"); SearchResponse response = null; try { for (int from = 0; from < numDocs; from++) { @@ -769,7 +770,7 @@ public void testReaderId() throws Exception { assertThat(response.getHits().getAt(0).getSourceAsMap().get("field1"), is("value1")); } } finally { - client().execute(ClearReaderAction.INSTANCE, new ClearReaderRequest(readerId)).actionGet(); + client().execute(CloseSearchContextAction.INSTANCE, new CloseSearchContextRequest(readerId)).actionGet(); } }