|
16 | 16 | import org.junit.Before; |
17 | 17 |
|
18 | 18 | import java.io.IOException; |
| 19 | +import java.util.List; |
19 | 20 | import java.util.Map; |
20 | 21 |
|
| 22 | +import static org.elasticsearch.test.ListMatcher.matchesList; |
| 23 | +import static org.elasticsearch.test.MapMatcher.matchesMap; |
21 | 24 | import static org.hamcrest.Matchers.equalTo; |
22 | 25 | import static org.hamcrest.core.StringContains.containsString; |
23 | 26 |
|
@@ -49,6 +52,27 @@ public void testWithInferenceNotConfigured() { |
49 | 52 | assertEquals(404, re.getResponse().getStatusLine().getStatusCode()); |
50 | 53 | } |
51 | 54 |
|
| 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 | + |
52 | 76 | @Before |
53 | 77 | public void setUpIndices() throws IOException { |
54 | 78 | var settings = Settings.builder().build(); |
@@ -82,6 +106,20 @@ public void setUpIndices() throws IOException { |
82 | 106 | } |
83 | 107 | """; |
84 | 108 | 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); |
85 | 123 | } |
86 | 124 |
|
87 | 125 | @Before |
|
0 commit comments