Skip to content

Commit ce8d632

Browse files
Unit test to validate copy_to for semantic_text field in esql
1 parent d597e50 commit ce8d632

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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

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

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

2122
import static org.hamcrest.Matchers.equalTo;
@@ -49,6 +50,25 @@ public void testWithInferenceNotConfigured() {
4950
assertEquals(404, re.getResponse().getStatusLine().getStatusCode());
5051
}
5152

53+
public void testCopyToWithSemanticText() throws IOException {
54+
assumeTrue("semantic text capability not available", EsqlCapabilities.Cap.SEMANTIC_TEXT_FIELD_CAPS.isEnabled());
55+
56+
var request = new Request("POST", "/test-semantic4/_doc/id-1");
57+
request.addParameter("refresh", "true");
58+
request.setJsonEntity("{\"text_field\": \"inference test\"}");
59+
assertEquals(201, adminClient().performRequest(request).getStatusLine().getStatusCode());
60+
61+
ensureGreen("test-semantic4");
62+
63+
String query = """
64+
from test-semantic4
65+
""";
66+
Map<String, Object> result = runEsqlQuery(query);
67+
68+
assertEquals(List.of("text_field", "semantic_text_field"), result.get("columns"));
69+
assertEquals(List.of("inference test", "inference test"), result.get("values"));
70+
}
71+
5272
@Before
5373
public void setUpIndices() throws IOException {
5474
var settings = Settings.builder().build();
@@ -82,6 +102,20 @@ public void setUpIndices() throws IOException {
82102
}
83103
""";
84104
createIndex(adminClient(), "test-semantic3", settings, mapping3);
105+
106+
String mapping4 = """
107+
"properties": {
108+
"semantic_text_field": {
109+
"type": "semantic_text",
110+
"inference_id": "test_sparse_inference"
111+
},
112+
"text_field": {
113+
"type": "text",
114+
"copy_to": "semantic_text_field"
115+
}
116+
}
117+
""";
118+
createIndex(adminClient(), "test-semantic4", settings, mapping4);
85119
}
86120

87121
@Before

0 commit comments

Comments
 (0)