Skip to content

Commit 85ddf1d

Browse files
more involved open PIT test
1 parent cdffc5b commit 85ddf1d

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

server/src/test/java/org/elasticsearch/rest/action/search/SearchPhaseCoordinatorAPMMetricsTests.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.common.bytes.BytesReference;
2323
import org.elasticsearch.common.settings.Settings;
2424
import org.elasticsearch.core.TimeValue;
25+
import org.elasticsearch.index.query.RangeQueryBuilder;
2526
import org.elasticsearch.plugins.Plugin;
2627
import org.elasticsearch.plugins.PluginsService;
2728
import org.elasticsearch.search.builder.PointInTimeBuilder;
@@ -42,6 +43,7 @@
4243

4344
public class SearchPhaseCoordinatorAPMMetricsTests extends ESSingleNodeTestCase {
4445
private static final String indexName = "test_coordinator_search_phase_metrics";
46+
private static final String secondIndexName = "test_coordinator_search_phase_metrics_2";
4547
private final int num_primaries = randomIntBetween(2, 7);
4648

4749
private static final String CAN_MATCH_SEARCH_PHASE_METRIC = "es.search_response.took_durations.can_match.histogram";
@@ -67,8 +69,22 @@ private void setUpIndex() throws Exception {
6769
);
6870
ensureGreen(indexName);
6971

70-
prepareIndex(indexName).setId("1").setSource("body", "doc1").setRefreshPolicy(IMMEDIATE).get();
71-
prepareIndex(indexName).setId("2").setSource("body", "doc2").setRefreshPolicy(IMMEDIATE).get();
72+
prepareIndex(indexName).setId("1").setSource("body", "doc1", "@timestamp", "2024-11-01").setRefreshPolicy(IMMEDIATE).get();
73+
prepareIndex(indexName).setId("2").setSource("body", "doc2", "@timestamp", "2024-12-01").setRefreshPolicy(IMMEDIATE).get();
74+
prepareIndex(indexName).setId("3").setSource("body", "doc3", "@timestamp", "2025-01-01").setRefreshPolicy(IMMEDIATE).get();
75+
76+
createIndex(
77+
secondIndexName,
78+
Settings.builder()
79+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, num_primaries)
80+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
81+
.build()
82+
);
83+
ensureGreen(secondIndexName);
84+
85+
prepareIndex(secondIndexName).setId("4").setSource("body", "doc1", "@timestamp", "2025-11-01").setRefreshPolicy(IMMEDIATE).get();
86+
prepareIndex(secondIndexName).setId("5").setSource("body", "doc2", "@timestamp", "2025-12-01").setRefreshPolicy(IMMEDIATE).get();
87+
prepareIndex(secondIndexName).setId("6").setSource("body", "doc3", "@timestamp", "2026-01-01").setRefreshPolicy(IMMEDIATE).get();
7288
}
7389

7490
@After
@@ -123,8 +139,8 @@ public void testPointInTime() {
123139
}
124140

125141
public void testPointInTimeWithPreFiltering() {
126-
OpenPointInTimeRequest request = new OpenPointInTimeRequest(indexName).keepAlive(TimeValue.timeValueMinutes(10));
127-
request.indexFilter(simpleQueryStringQuery("doc1"));
142+
OpenPointInTimeRequest request = new OpenPointInTimeRequest(indexName, secondIndexName).keepAlive(TimeValue.timeValueMinutes(10));
143+
request.indexFilter(new RangeQueryBuilder("@timestamp").gte("2025-07-01"));
128144
OpenPointInTimeResponse response = client().execute(TransportOpenPointInTimeAction.TYPE, request).actionGet();
129145
BytesReference pointInTimeId = response.getPointInTimeId();
130146

@@ -134,8 +150,8 @@ public void testPointInTimeWithPreFiltering() {
134150
.setPointInTime(new PointInTimeBuilder(pointInTimeId))
135151
.setSize(1)
136152
.setPreFilterShardSize(1)
137-
.setQuery(simpleQueryStringQuery("doc1")),
138-
"1"
153+
.setQuery(simpleQueryStringQuery("doc3")),
154+
"6"
139155
);
140156
assertMeasurements(List.of(OPEN_PIT_SEARCH_PHASE_METRIC, QUERY_SEARCH_PHASE_METRIC, FETCH_SEARCH_PHASE_METRIC), 1);
141157
assertMeasurements(

0 commit comments

Comments
 (0)