Skip to content

Commit 5632821

Browse files
committed
Added remote index search test for rrf retriever
1 parent a84eac4 commit 5632821

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

x-pack/plugin/rank-rrf/src/test/java/org/elasticsearch/xpack/rank/rrf/RRFRetrieverBuilderTests.java

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.xcontent.json.JsonXContent;
3535

3636
import java.io.IOException;
37+
import java.util.HashMap;
3738
import java.util.HashSet;
3839
import java.util.List;
3940
import java.util.Map;
@@ -87,7 +88,7 @@ public void testRetrieverExtractionErrors() throws IOException {
8788
public void testSimplifiedParamsRewrite() {
8889
final String indexName = "test-index";
8990
final List<String> testInferenceFields = List.of("semantic_field_1", "semantic_field_2");
90-
final ResolvedIndices resolvedIndices = createMockResolvedIndices(indexName, testInferenceFields);
91+
final ResolvedIndices resolvedIndices = createMockResolvedIndices(indexName, testInferenceFields, null);
9192
final QueryRewriteContext queryRewriteContext = new QueryRewriteContext(
9293
parserConfig(),
9394
null,
@@ -162,6 +163,36 @@ public void testSimplifiedParamsRewrite() {
162163
);
163164
}
164165

166+
public void testSearchRemoteIndex() {
167+
final ResolvedIndices resolvedIndices = createMockResolvedIndices(
168+
"local-index",
169+
List.of(),
170+
Map.of("remote-cluster", "remote-index")
171+
);
172+
final QueryRewriteContext queryRewriteContext = new QueryRewriteContext(
173+
parserConfig(),
174+
null,
175+
null,
176+
resolvedIndices,
177+
new PointInTimeBuilder(new BytesArray("pitid")),
178+
null
179+
);
180+
181+
RRFRetrieverBuilder rrfRetrieverBuilder = new RRFRetrieverBuilder(
182+
null,
183+
null,
184+
"foo",
185+
DEFAULT_RANK_WINDOW_SIZE,
186+
RRFRetrieverBuilder.DEFAULT_RANK_CONSTANT
187+
);
188+
189+
IllegalArgumentException iae = expectThrows(
190+
IllegalArgumentException.class,
191+
() -> rrfRetrieverBuilder.doRewrite(queryRewriteContext)
192+
);
193+
assertEquals("[rrf] does not support the simplified query format when querying remote indices", iae.getMessage());
194+
}
195+
165196
@Override
166197
protected NamedXContentRegistry xContentRegistry() {
167198
List<NamedXContentRegistry.Entry> entries = new SearchModule(Settings.EMPTY, List.of()).getNamedXContents();
@@ -183,8 +214,12 @@ protected NamedXContentRegistry xContentRegistry() {
183214
return new NamedXContentRegistry(entries);
184215
}
185216

186-
private static ResolvedIndices createMockResolvedIndices(String indexName, List<String> inferenceFields) {
187-
Index index = new Index(indexName, randomAlphaOfLength(10));
217+
private static ResolvedIndices createMockResolvedIndices(
218+
String localIndexName,
219+
List<String> inferenceFields,
220+
Map<String, String> remoteIndexNames
221+
) {
222+
Index index = new Index(localIndexName, randomAlphaOfLength(10));
188223
IndexMetadata.Builder indexMetadataBuilder = IndexMetadata.builder(index.getName())
189224
.settings(
190225
Settings.builder()
@@ -200,9 +235,16 @@ private static ResolvedIndices createMockResolvedIndices(String indexName, List<
200235
);
201236
}
202237

238+
Map<String, OriginalIndices> remoteIndices = new HashMap<>();
239+
if (remoteIndexNames != null) {
240+
for (Map.Entry<String, String> entry : remoteIndexNames.entrySet()) {
241+
remoteIndices.put(entry.getKey(), new OriginalIndices(new String[] { entry.getValue() }, IndicesOptions.DEFAULT));
242+
}
243+
}
244+
203245
return new MockResolvedIndices(
204-
Map.of(),
205-
new OriginalIndices(new String[] { indexName }, IndicesOptions.DEFAULT),
246+
remoteIndices,
247+
new OriginalIndices(new String[] { localIndexName }, IndicesOptions.DEFAULT),
206248
Map.of(index, indexMetadataBuilder.build())
207249
);
208250
}

0 commit comments

Comments
 (0)