|
7 | 7 |
|
8 | 8 | package org.elasticsearch.xpack.inference.integration; |
9 | 9 |
|
10 | | -import org.elasticsearch.action.DocWriteResponse;; |
| 10 | +import org.elasticsearch.action.DocWriteResponse; |
11 | 11 | import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; |
12 | 12 | import org.elasticsearch.action.search.SearchRequest; |
13 | 13 | import org.elasticsearch.common.settings.Settings; |
14 | 14 | import org.elasticsearch.core.TimeValue; |
15 | 15 | import org.elasticsearch.index.IndexVersion; |
| 16 | +import org.elasticsearch.index.mapper.InferenceMetadataFieldsMapper; |
16 | 17 | import org.elasticsearch.license.LicenseSettings; |
17 | 18 | import org.elasticsearch.plugins.Plugin; |
18 | 19 | import org.elasticsearch.search.builder.SearchSourceBuilder; |
@@ -45,7 +46,7 @@ public class SemanticTextIndexVersionIT extends ESIntegTestCase { |
45 | 46 | private static final IndexVersion SEMANTIC_TEXT_INTRODUCED_VERSION = IndexVersion.fromId(8512000); |
46 | 47 |
|
47 | 48 | private Set<IndexVersion> availableVersions; |
48 | | - private static final int MIN_NUMBER_OF_TESTS_TO_RUN = 1; |
| 49 | + private static final int MIN_NUMBER_OF_TESTS_TO_RUN = 10; |
49 | 50 |
|
50 | 51 | @Before |
51 | 52 | public void setup() throws Exception { |
@@ -154,16 +155,25 @@ public void testSemanticText() throws Exception { |
154 | 155 | assertHitCount(response, 1L); |
155 | 156 | }); |
156 | 157 |
|
157 | | - //Semantic Search with highlighter |
158 | | - SearchSourceBuilder sourceHighlighterBuilder = new SearchSourceBuilder() |
159 | | - .query(new SemanticQueryBuilder("semantic_field", "inference")) |
160 | | - .highlighter(new HighlightBuilder().field(new HighlightBuilder.Field("semantic_field").numOfFragments(1))) |
161 | | - .trackTotalHits(true); |
162 | | - |
163 | | - assertResponse(client().search(new SearchRequest(indexName).source(sourceBuilder)), response -> { |
164 | | - assertHitCount(response, 1L); |
165 | | - assertHighlight(response, 0, "semantic_field", 0, 2, equalTo("inference")); |
166 | | - }); |
| 158 | + //Semantic Search with highlighter only available from 8.18 and 9.0 |
| 159 | + Settings settings = client().admin() |
| 160 | + .indices() |
| 161 | + .prepareGetSettings(TimeValue.THIRTY_SECONDS, indexName) |
| 162 | + .get() |
| 163 | + .getIndexToSettings() |
| 164 | + .get(indexName); |
| 165 | + |
| 166 | + if (InferenceMetadataFieldsMapper.isEnabled(settings)) { |
| 167 | + SearchSourceBuilder sourceHighlighterBuilder = new SearchSourceBuilder() |
| 168 | + .query(new SemanticQueryBuilder("semantic_field", "inference")) |
| 169 | + .highlighter(new HighlightBuilder().field("semantic_field")) |
| 170 | + .trackTotalHits(true); |
| 171 | + |
| 172 | + assertResponse(client().search(new SearchRequest(indexName).source(sourceHighlighterBuilder)), response -> { |
| 173 | + assertHighlight(response, 0, "semantic_field", 0, 2, equalTo("inference test")); |
| 174 | + assertHighlight(response, 0, "semantic_field", 1, 2, equalTo("another inference test")); |
| 175 | + }); |
| 176 | + } |
167 | 177 | } |
168 | 178 | } |
169 | 179 | } |
0 commit comments