Skip to content

Commit 6c6d15b

Browse files
committed
Fixed ES|QL test
1 parent a69b474 commit 6c6d15b

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/SemanticMatchTestCase.java

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,28 @@ public abstract class SemanticMatchTestCase extends ESRestTestCase {
3434
public void testWithMultipleInferenceIds() throws IOException {
3535
assumeTrue("semantic text capability not available", EsqlCapabilities.Cap.SEMANTIC_TEXT_FIELD_CAPS.isEnabled());
3636

37+
var request1 = new Request("POST", "/test-semantic1/_doc/id-1");
38+
request1.addParameter("refresh", "true");
39+
request1.setJsonEntity("{\"semantic_text_field\": \"inference test 1\"}");
40+
assertEquals(201, adminClient().performRequest(request1).getStatusLine().getStatusCode());
41+
42+
var request2 = new Request("POST", "/test-semantic2/_doc/id-2");
43+
request2.addParameter("refresh", "true");
44+
request2.setJsonEntity("{\"semantic_text_field\": \"inference test 2\"}");
45+
assertEquals(201, adminClient().performRequest(request2).getStatusLine().getStatusCode());
46+
3747
String query = """
3848
from test-semantic1,test-semantic2
3949
| where match(semantic_text_field, "something")
50+
| SORT semantic_text_field ASC
4051
""";
41-
ResponseException re = expectThrows(ResponseException.class, () -> runEsqlQuery(query));
42-
43-
assertThat(re.getMessage(), containsString("Field [semantic_text_field] has multiple inference IDs associated with it"));
52+
Map<String, Object> result = runEsqlQuery(query);
4453

45-
assertEquals(400, re.getResponse().getStatusLine().getStatusCode());
54+
assertResultMap(
55+
result,
56+
matchesList().item(matchesMap().entry("name", "semantic_text_field").entry("type", "text")),
57+
matchesList(List.of(List.of("inference test 1"), List.of("inference test 2")))
58+
);
4659
}
4760

4861
public void testWithInferenceNotConfigured() {
@@ -128,6 +141,28 @@ public void setUpIndices() throws IOException {
128141
createIndex(adminClient(), "test-semantic4", settings, mapping4);
129142
}
130143

144+
@Before
145+
public void setUpSparseEmbeddingInferenceEndpoint() throws IOException {
146+
Request request = new Request("PUT", "_inference/sparse_embedding/test_sparse_inference");
147+
request.setJsonEntity("""
148+
{
149+
"service": "test_service",
150+
"service_settings": {
151+
"model": "my_model",
152+
"api_key": "abc64"
153+
},
154+
"task_settings": {
155+
}
156+
}
157+
""");
158+
try {
159+
adminClient().performRequest(request);
160+
} catch (ResponseException exc) {
161+
// in case the removal failed
162+
assertThat(exc.getResponse().getStatusLine().getStatusCode(), equalTo(400));
163+
}
164+
}
165+
131166
@Before
132167
public void setUpTextEmbeddingInferenceEndpoint() throws IOException {
133168
Request request = new Request("PUT", "_inference/text_embedding/test_dense_inference");
@@ -155,6 +190,15 @@ public void setUpTextEmbeddingInferenceEndpoint() throws IOException {
155190
public void wipeData() throws IOException {
156191
adminClient().performRequest(new Request("DELETE", "*"));
157192

193+
try {
194+
adminClient().performRequest(new Request("DELETE", "_inference/test_sparse_inference"));
195+
} catch (ResponseException e) {
196+
// 404 here means the endpoint was not created
197+
if (e.getResponse().getStatusLine().getStatusCode() != 404) {
198+
throw e;
199+
}
200+
}
201+
158202
try {
159203
adminClient().performRequest(new Request("DELETE", "_inference/test_dense_inference"));
160204
} catch (ResponseException e) {

0 commit comments

Comments
 (0)