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
This commit is contained in:
Samiul Monir 2025-06-03 09:04:26 -04:00 committed by GitHub
parent dc3d515226
commit fa152a9182
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 38 additions and 0 deletions

View File

@ -16,8 +16,11 @@ import org.junit.After;
import org.junit.Before;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.test.ListMatcher.matchesList;
import static org.elasticsearch.test.MapMatcher.matchesMap;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.StringContains.containsString;
@ -49,6 +52,27 @@ public abstract class SemanticMatchTestCase extends ESRestTestCase {
assertEquals(404, re.getResponse().getStatusLine().getStatusCode());
}
public void testCopyToWithSemanticText() throws IOException {
assumeTrue("semantic text capability not available", EsqlCapabilities.Cap.SEMANTIC_TEXT_FIELD_CAPS.isEnabled());
var request = new Request("POST", "/test-semantic4/_doc/id-1");
request.addParameter("refresh", "true");
request.setJsonEntity("{\"text_field\": \"inference test\"}");
assertEquals(201, adminClient().performRequest(request).getStatusLine().getStatusCode());
String query = """
from test-semantic4
""";
Map<String, Object> result = runEsqlQuery(query);
assertResultMap(
result,
matchesList().item(matchesMap().entry("name", "semantic_text_field").entry("type", "text"))
.item(matchesMap().entry("name", "text_field").entry("type", "text")),
List.of(List.of("inference test", "inference test"))
);
}
@Before
public void setUpIndices() throws IOException {
var settings = Settings.builder().build();
@ -82,6 +106,20 @@ public abstract class SemanticMatchTestCase extends ESRestTestCase {
}
""";
createIndex(adminClient(), "test-semantic3", settings, mapping3);
String mapping4 = """
"properties": {
"semantic_text_field": {
"type": "semantic_text",
"inference_id": "test_dense_inference"
},
"text_field": {
"type": "text",
"copy_to": "semantic_text_field"
}
}
""";
createIndex(adminClient(), "test-semantic4", settings, mapping4);
}
@Before