Skip to content

Commit fa152a9

Browse files
Unit test to validate copy_to for semantic_text field in esql (#128795)
* Unit test to validate copy_to for semantic_text field in esql * Fix the unit test * fix test for single node
1 parent dc3d515 commit fa152a9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
import org.junit.Before;
1717

1818
import java.io.IOException;
19+
import java.util.List;
1920
import java.util.Map;
2021

22+
import static org.elasticsearch.test.ListMatcher.matchesList;
23+
import static org.elasticsearch.test.MapMatcher.matchesMap;
2124
import static org.hamcrest.Matchers.equalTo;
2225
import static org.hamcrest.core.StringContains.containsString;
2326

@@ -49,6 +52,27 @@ public void testWithInferenceNotConfigured() {
4952
assertEquals(404, re.getResponse().getStatusLine().getStatusCode());
5053
}
5154

55+
public void testCopyToWithSemanticText() throws IOException {
56+
assumeTrue("semantic text capability not available", EsqlCapabilities.Cap.SEMANTIC_TEXT_FIELD_CAPS.isEnabled());
57+
58+
var request = new Request("POST", "/test-semantic4/_doc/id-1");
59+
request.addParameter("refresh", "true");
60+
request.setJsonEntity("{\"text_field\": \"inference test\"}");
61+
assertEquals(201, adminClient().performRequest(request).getStatusLine().getStatusCode());
62+
63+
String query = """
64+
from test-semantic4
65+
""";
66+
Map<String, Object> result = runEsqlQuery(query);
67+
68+
assertResultMap(
69+
result,
70+
matchesList().item(matchesMap().entry("name", "semantic_text_field").entry("type", "text"))
71+
.item(matchesMap().entry("name", "text_field").entry("type", "text")),
72+
List.of(List.of("inference test", "inference test"))
73+
);
74+
}
75+
5276
@Before
5377
public void setUpIndices() throws IOException {
5478
var settings = Settings.builder().build();
@@ -82,6 +106,20 @@ public void setUpIndices() throws IOException {
82106
}
83107
""";
84108
createIndex(adminClient(), "test-semantic3", settings, mapping3);
109+
110+
String mapping4 = """
111+
"properties": {
112+
"semantic_text_field": {
113+
"type": "semantic_text",
114+
"inference_id": "test_dense_inference"
115+
},
116+
"text_field": {
117+
"type": "text",
118+
"copy_to": "semantic_text_field"
119+
}
120+
}
121+
""";
122+
createIndex(adminClient(), "test-semantic4", settings, mapping4);
85123
}
86124

87125
@Before

0 commit comments

Comments
 (0)