|
46 | 46 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapperTests.addSemanticTextInferenceResults; |
47 | 47 | import static org.elasticsearch.xpack.inference.mapper.SemanticTextFieldTests.randomSemanticText; |
48 | 48 | import static org.hamcrest.CoreMatchers.equalTo; |
49 | | -import static org.hamcrest.CoreMatchers.instanceOf; |
50 | 49 | import static org.hamcrest.CoreMatchers.notNullValue; |
51 | 50 |
|
52 | 51 | public class SemanticTextUpgradeIT extends AbstractUpgradeTestCase { |
@@ -123,10 +122,10 @@ private void performIndexQueryHighlightOps() throws IOException { |
123 | 122 | indexDoc(DOC_2_ID, DOC_VALUES.get(DOC_2_ID)); |
124 | 123 |
|
125 | 124 | ObjectPath sparseQueryObjectPath = semanticQuery(SPARSE_FIELD, SPARSE_MODEL, "test value", 3); |
126 | | - assertQueryResponse(sparseQueryObjectPath, SPARSE_FIELD); |
| 125 | + assertQueryResponseWithHighlights(sparseQueryObjectPath, SPARSE_FIELD); |
127 | 126 |
|
128 | 127 | ObjectPath denseQueryObjectPath = semanticQuery(DENSE_FIELD, DENSE_MODEL, "test value", 3); |
129 | | - assertQueryResponse(denseQueryObjectPath, DENSE_FIELD); |
| 128 | + assertQueryResponseWithHighlights(denseQueryObjectPath, DENSE_FIELD); |
130 | 129 | } |
131 | 130 |
|
132 | 131 | private String getIndexName() { |
@@ -227,24 +226,20 @@ private ObjectPath semanticQuery(String field, Model fieldModel, String query, I |
227 | 226 | return assertOKAndCreateObjectPath(response); |
228 | 227 | } |
229 | 228 |
|
230 | | - @SuppressWarnings("unchecked") |
231 | | - private static void assertQueryResponse(ObjectPath queryObjectPath, String field) throws IOException { |
| 229 | + private static void assertQueryResponseWithHighlights(ObjectPath queryObjectPath, String field) throws IOException { |
232 | 230 | assertThat(queryObjectPath.evaluate("hits.total.value"), equalTo(2)); |
233 | 231 | assertThat(queryObjectPath.evaluateArraySize("hits.hits"), equalTo(2)); |
234 | 232 |
|
235 | 233 | Set<String> docIds = new HashSet<>(); |
236 | | - List<Object> hits = queryObjectPath.evaluate("hits.hits"); |
237 | | - for (Object hit : hits) { |
238 | | - assertThat(hit, instanceOf(Map.class)); |
239 | | - Map<String, Object> hitMap = (Map<String, Object>) hit; |
240 | | - |
241 | | - String id = (String) hitMap.get("_id"); |
| 234 | + List<Map<String, Object>> hits = queryObjectPath.evaluate("hits.hits"); |
| 235 | + for (Map<String, Object> hit : hits) { |
| 236 | + String id = ObjectPath.evaluate(hit, "_id"); |
242 | 237 | assertThat(id, notNullValue()); |
243 | 238 | docIds.add(id); |
244 | 239 |
|
245 | 240 | List<String> expectedHighlight = DOC_VALUES.get(id); |
246 | 241 | assertThat(expectedHighlight, notNullValue()); |
247 | | - assertThat(((Map<String, Object>) hitMap.get("highlight")).get(field), equalTo(expectedHighlight)); |
| 242 | + assertThat(ObjectPath.evaluate(hit, "highlight." + field), equalTo(expectedHighlight)); |
248 | 243 | } |
249 | 244 |
|
250 | 245 | assertThat(docIds, equalTo(Set.of(DOC_1_ID, DOC_2_ID))); |
|
0 commit comments