Skip to content

Commit d176446

Browse files
committed
Doc value refactoring
1 parent b246cba commit d176446

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/SemanticTextUpgradeIT.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ public class SemanticTextUpgradeIT extends AbstractUpgradeTestCase {
5454
private static final String SPARSE_FIELD = "sparse_field";
5555
private static final String DENSE_FIELD = "dense_field";
5656

57+
private static final String DOC_1_ID = "doc_1";
58+
private static final String DOC_2_ID = "doc_2";
59+
private static final Map<String, List<String>> DOC_VALUES = Map.of(
60+
DOC_1_ID,
61+
List.of("a test value", "with multiple test values"),
62+
DOC_2_ID,
63+
List.of("another test value")
64+
);
65+
5766
private static Model SPARSE_MODEL;
5867
private static Model DENSE_MODEL;
5968

@@ -107,11 +116,11 @@ private void createAndPopulateIndex() throws IOException {
107116
);
108117
assertThat(response.isAcknowledged(), equalTo(true));
109118

110-
indexDoc("doc_1", List.of("a test value", "with multiple test values"));
119+
indexDoc(DOC_1_ID, DOC_VALUES.get(DOC_1_ID));
111120
}
112121

113122
private void performIndexQueryHighlightOps() throws IOException {
114-
indexDoc("doc_2", List.of("another test value"));
123+
indexDoc(DOC_2_ID, DOC_VALUES.get(DOC_2_ID));
115124

116125
ObjectPath sparseQueryObjectPath = semanticQuery(SPARSE_FIELD, SPARSE_MODEL, "test value", 3);
117126
assertQueryResponse(sparseQueryObjectPath, SPARSE_FIELD);
@@ -186,8 +195,7 @@ private ObjectPath semanticQuery(String field, Model fieldModel, String query, I
186195
Arrays.fill(queryVector, 1.0f);
187196
}
188197

189-
// TODO: Don't hard-code K
190-
yield new KnnVectorQueryBuilder(embeddingsFieldName, queryVector, 10, null, null, null);
198+
yield new KnnVectorQueryBuilder(embeddingsFieldName, queryVector, DOC_VALUES.size(), null, null, null);
191199
}
192200
default -> throw new UnsupportedOperationException("Unhandled task type [" + fieldModel.getTaskType() + "]");
193201
};
@@ -221,13 +229,6 @@ private ObjectPath semanticQuery(String field, Model fieldModel, String query, I
221229

222230
@SuppressWarnings("unchecked")
223231
private static void assertQueryResponse(ObjectPath queryObjectPath, String field) throws IOException {
224-
final Map<String, List<String>> expectedHighlights = Map.of(
225-
"doc_1",
226-
List.of("a test value", "with multiple test values"),
227-
"doc_2",
228-
List.of("another test value")
229-
);
230-
231232
assertThat(queryObjectPath.evaluate("hits.total.value"), equalTo(2));
232233
assertThat(queryObjectPath.evaluateArraySize("hits.hits"), equalTo(2));
233234

@@ -241,11 +242,11 @@ private static void assertQueryResponse(ObjectPath queryObjectPath, String field
241242
assertThat(id, notNullValue());
242243
docIds.add(id);
243244

244-
List<String> expectedHighlight = expectedHighlights.get(id);
245+
List<String> expectedHighlight = DOC_VALUES.get(id);
245246
assertThat(expectedHighlight, notNullValue());
246247
assertThat(((Map<String, Object>) hitMap.get("highlight")).get(field), equalTo(expectedHighlight));
247248
}
248249

249-
assertThat(docIds, equalTo(Set.of("doc_1", "doc_2")));
250+
assertThat(docIds, equalTo(Set.of(DOC_1_ID, DOC_2_ID)));
250251
}
251252
}

0 commit comments

Comments
 (0)