-
Couldn't load subscription status.
- Fork 25.6k
Skip search shards with INDEX_REFRESH_BLOCK #129132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
2aa74e3
12b6b81
9c705cd
1c75721
1ecc447
cdb4bc1
b7ade2d
cd991c2
5f50d5c
3f86fb8
0edc27c
9de6f06
be37bf6
17706e2
8759a07
bf8a2be
8887609
0f0200a
7689263
598e906
4cdfbd0
76ecade
86c9a5d
7200edc
d72600b
61d40c4
51d5196
24f2770
b33a14f
e10d59b
31d7dce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.search; | ||
|
|
||
| import org.elasticsearch.action.admin.indices.readonly.AddIndexBlockRequest; | ||
| import org.elasticsearch.action.admin.indices.readonly.TransportAddIndexBlockAction; | ||
| import org.elasticsearch.action.search.ClosePointInTimeRequest; | ||
| import org.elasticsearch.action.search.OpenPointInTimeRequest; | ||
| import org.elasticsearch.action.search.SearchRequest; | ||
| import org.elasticsearch.action.search.TransportClosePointInTimeAction; | ||
| import org.elasticsearch.action.search.TransportOpenPointInTimeAction; | ||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.common.bytes.BytesReference; | ||
| import org.elasticsearch.core.TimeValue; | ||
| import org.elasticsearch.index.query.QueryBuilders; | ||
| import org.elasticsearch.search.builder.PointInTimeBuilder; | ||
| import org.elasticsearch.search.builder.SearchSourceBuilder; | ||
| import org.elasticsearch.test.ESIntegTestCase; | ||
|
|
||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; | ||
|
|
||
| public class SearchWithIndexBlocksIT extends ESIntegTestCase { | ||
|
|
||
| public void testSearchIndexWithIndexRefreshBlock() { | ||
| createIndex("test"); | ||
|
|
||
| var addIndexBlockRequest = new AddIndexBlockRequest(IndexMetadata.APIBlock.REFRESH, "test"); | ||
| client().execute(TransportAddIndexBlockAction.TYPE, addIndexBlockRequest).actionGet(); | ||
|
||
|
|
||
| indexRandom( | ||
| true, | ||
| prepareIndex("test").setId("1").setSource("field", "value"), | ||
| prepareIndex("test").setId("2").setSource("field", "value"), | ||
| prepareIndex("test").setId("3").setSource("field", "value"), | ||
| prepareIndex("test").setId("4").setSource("field", "value"), | ||
| prepareIndex("test").setId("5").setSource("field", "value"), | ||
| prepareIndex("test").setId("6").setSource("field", "value") | ||
| ); | ||
|
|
||
| assertHitCount(prepareSearch().setQuery(QueryBuilders.matchAllQuery()), 0); | ||
| } | ||
|
|
||
| public void testSearchMultipleIndicesEachWithAnIndexRefreshBlock() { | ||
|
||
| createIndex("test"); | ||
| createIndex("test2"); | ||
|
|
||
| var addIndexBlockRequest = new AddIndexBlockRequest(IndexMetadata.APIBlock.REFRESH, "test", "test2"); | ||
| client().execute(TransportAddIndexBlockAction.TYPE, addIndexBlockRequest).actionGet(); | ||
|
|
||
| indexRandom( | ||
| true, | ||
| prepareIndex("test").setId("1").setSource("field", "value"), | ||
| prepareIndex("test").setId("2").setSource("field", "value"), | ||
| prepareIndex("test").setId("3").setSource("field", "value"), | ||
| prepareIndex("test").setId("4").setSource("field", "value"), | ||
| prepareIndex("test").setId("5").setSource("field", "value"), | ||
| prepareIndex("test").setId("6").setSource("field", "value"), | ||
| prepareIndex("test2").setId("1").setSource("field", "value"), | ||
| prepareIndex("test2").setId("2").setSource("field", "value"), | ||
| prepareIndex("test2").setId("3").setSource("field", "value"), | ||
| prepareIndex("test2").setId("4").setSource("field", "value"), | ||
| prepareIndex("test2").setId("5").setSource("field", "value"), | ||
| prepareIndex("test2").setId("6").setSource("field", "value") | ||
| ); | ||
|
|
||
| assertHitCount(prepareSearch().setQuery(QueryBuilders.matchAllQuery()), 0); | ||
| } | ||
|
|
||
| public void testSearchMultipleIndicesWithOneIndexRefreshBlock() { | ||
| createIndex("test"); | ||
| createIndex("test2"); | ||
|
|
||
| // Only block test | ||
| var addIndexBlockRequest = new AddIndexBlockRequest(IndexMetadata.APIBlock.REFRESH, "test"); | ||
| client().execute(TransportAddIndexBlockAction.TYPE, addIndexBlockRequest).actionGet(); | ||
|
|
||
| indexRandom( | ||
| true, | ||
| prepareIndex("test").setId("1").setSource("field", "value"), | ||
| prepareIndex("test").setId("2").setSource("field", "value"), | ||
| prepareIndex("test").setId("3").setSource("field", "value"), | ||
| prepareIndex("test").setId("4").setSource("field", "value"), | ||
| prepareIndex("test").setId("5").setSource("field", "value"), | ||
| prepareIndex("test").setId("6").setSource("field", "value"), | ||
| prepareIndex("test2").setId("1").setSource("field", "value"), | ||
| prepareIndex("test2").setId("2").setSource("field", "value"), | ||
| prepareIndex("test2").setId("3").setSource("field", "value"), | ||
| prepareIndex("test2").setId("4").setSource("field", "value"), | ||
| prepareIndex("test2").setId("5").setSource("field", "value"), | ||
| prepareIndex("test2").setId("6").setSource("field", "value") | ||
| ); | ||
|
|
||
| // We should get test2 results (not blocked) | ||
| assertHitCount(prepareSearch().setQuery(QueryBuilders.matchAllQuery()), 6); | ||
| } | ||
|
|
||
| public void testOpenPITWithIndexRefreshBlock() { | ||
| createIndex("test"); | ||
|
|
||
| var addIndexBlockRequest = new AddIndexBlockRequest(IndexMetadata.APIBlock.REFRESH, "test"); | ||
| client().execute(TransportAddIndexBlockAction.TYPE, addIndexBlockRequest).actionGet(); | ||
|
|
||
| indexRandom( | ||
| true, | ||
| prepareIndex("test").setId("1").setSource("field", "value"), | ||
| prepareIndex("test").setId("2").setSource("field", "value"), | ||
| prepareIndex("test").setId("3").setSource("field", "value"), | ||
| prepareIndex("test").setId("4").setSource("field", "value"), | ||
| prepareIndex("test").setId("5").setSource("field", "value"), | ||
| prepareIndex("test").setId("6").setSource("field", "value") | ||
| ); | ||
|
|
||
| BytesReference pitId = null; | ||
| try { | ||
| OpenPointInTimeRequest openPITRequest = new OpenPointInTimeRequest("test").keepAlive(TimeValue.timeValueSeconds(10)) | ||
| .allowPartialSearchResults(true); | ||
| pitId = client().execute(TransportOpenPointInTimeAction.TYPE, openPITRequest).actionGet().getPointInTimeId(); | ||
| SearchRequest searchRequest = new SearchRequest().source( | ||
| new SearchSourceBuilder().pointInTimeBuilder(new PointInTimeBuilder(pitId).setKeepAlive(TimeValue.timeValueSeconds(10))) | ||
| ); | ||
| assertHitCount(client().search(searchRequest), 0); | ||
| } finally { | ||
| if (pitId != null) { | ||
| client().execute(TransportClosePointInTimeAction.TYPE, new ClosePointInTimeRequest(pitId)).actionGet(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also want to have ESQL test for this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm tracking that to be a followup task.