Skip to content

Commit ab82d74

Browse files
ioanatiaChrisHegartyelasticmachine
authored
ES|QL Add initial support for semantic_text field type (#113920) (#115256)
* Add initial support for semantic_text field type * Update docs/changelog/113920.yaml * More tests and fixes * Use mock inference service * Fix tests * Spotless * Fix mixed-cluster and multi-clusters tests * sort * Attempt another fix for bwc tests * Spotless * Fix merge * Attempt another fix * Don't load the inference-service-test plugin for mixed versions/clusters * Add more tests, address review comments * trivial * revert * post-merge fix block loader * post-merge fix compile * add mixed version testing * whitespace * fix MultiClusterSpecIT * add more fields to mapping * Revert mixed version testing * whitespace --------- Co-authored-by: ChrisHegarty <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 21312da commit ab82d74

File tree

26 files changed

+490
-35
lines changed

26 files changed

+490
-35
lines changed

docs/changelog/113920.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 113920
2+
summary: Add initial support for `semantic_text` field type
3+
area: Search
4+
type: enhancement
5+
issues: []

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/plugin/EsqlCorePlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
public class EsqlCorePlugin extends Plugin implements ExtensiblePlugin {
1515
public static final FeatureFlag DATE_NANOS_FEATURE_FLAG = new FeatureFlag("esql_date_nanos");
1616

17+
public static final FeatureFlag SEMANTIC_TEXT_FEATURE_FLAG = new FeatureFlag("esql_semantic_text");
1718
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/DataType.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,14 @@ public enum DataType {
194194
* inside alongside time-series aggregations. These fields are not parsable from the
195195
* mapping and should be hidden from users.
196196
*/
197-
PARTIAL_AGG(builder().esType("partial_agg").unknownSize());
197+
PARTIAL_AGG(builder().esType("partial_agg").unknownSize()),
198+
/**
199+
* String fields that are split into chunks, where each chunk has attached embeddings
200+
* used for semantic search. Generally ESQL only sees {@code semantic_text} fields when
201+
* loaded from the index and ESQL will load these fields as strings without their attached
202+
* chunks or embeddings.
203+
*/
204+
SEMANTIC_TEXT(builder().esType("semantic_text").unknownSize());
198205

199206
/**
200207
* Types that are actively being built. These types are not returned
@@ -203,7 +210,8 @@ public enum DataType {
203210
* check that sending them to a function produces a sane error message.
204211
*/
205212
public static final Map<DataType, FeatureFlag> UNDER_CONSTRUCTION = Map.ofEntries(
206-
Map.entry(DATE_NANOS, EsqlCorePlugin.DATE_NANOS_FEATURE_FLAG)
213+
Map.entry(DATE_NANOS, EsqlCorePlugin.DATE_NANOS_FEATURE_FLAG),
214+
Map.entry(SEMANTIC_TEXT, EsqlCorePlugin.SEMANTIC_TEXT_FEATURE_FLAG)
207215
);
208216

209217
private final String typeName;

x-pack/plugin/esql/qa/server/mixed-cluster/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/mixed/MixedClusterEsqlSpecIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,9 @@ protected boolean supportsAsync() {
8686
protected boolean enableRoundingDoubleValuesOnAsserting() {
8787
return true;
8888
}
89+
90+
@Override
91+
protected boolean supportsInferenceTestService() {
92+
return false;
93+
}
8994
}

x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,9 @@ static boolean hasIndexMetadata(String query) {
261261
protected boolean enableRoundingDoubleValuesOnAsserting() {
262262
return true;
263263
}
264+
265+
@Override
266+
protected boolean supportsInferenceTestService() {
267+
return false;
268+
}
264269
}

x-pack/plugin/esql/qa/server/multi-node/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies {
1111

1212
clusterPlugins project(':plugins:mapper-size')
1313
clusterPlugins project(':plugins:mapper-murmur3')
14+
clusterPlugins project(':x-pack:plugin:inference:qa:test-service-plugin')
1415
}
1516

1617
GradleUtils.extendSourceSet(project, "javaRestTest", "yamlRestTest")

x-pack/plugin/esql/qa/server/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/EsqlSpecIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public class EsqlSpecIT extends EsqlSpecTestCase {
1616
@ClassRule
17-
public static ElasticsearchCluster cluster = Clusters.testCluster(spec -> {});
17+
public static ElasticsearchCluster cluster = Clusters.testCluster(spec -> spec.plugin("inference-service-test"));
1818

1919
@Override
2020
protected String getTestRestCluster() {

x-pack/plugin/esql/qa/server/single-node/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies {
2222

2323
clusterPlugins project(':plugins:mapper-size')
2424
clusterPlugins project(':plugins:mapper-murmur3')
25+
clusterPlugins project(':x-pack:plugin:inference:qa:test-service-plugin')
2526
}
2627

2728
restResources {

x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/EsqlSpecIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
1919
public class EsqlSpecIT extends EsqlSpecTestCase {
2020
@ClassRule
21-
public static ElasticsearchCluster cluster = Clusters.testCluster();
21+
public static ElasticsearchCluster cluster = Clusters.testCluster(spec -> spec.plugin("inference-service-test"));
2222

2323
@Override
2424
protected String getTestRestCluster() {

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@
6565
import static org.elasticsearch.xpack.esql.CsvTestUtils.ExpectedResults;
6666
import static org.elasticsearch.xpack.esql.CsvTestUtils.isEnabled;
6767
import static org.elasticsearch.xpack.esql.CsvTestUtils.loadCsvSpecValues;
68-
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.CSV_DATASET_MAP;
68+
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.availableDatasetsForEs;
69+
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.clusterHasInferenceEndpoint;
70+
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.createInferenceEndpoint;
71+
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.deleteInferenceEndpoint;
6972
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.loadDataSetIntoEs;
7073
import static org.elasticsearch.xpack.esql.EsqlTestUtils.classpathResources;
7174

@@ -129,7 +132,11 @@ protected EsqlSpecTestCase(
129132

130133
@Before
131134
public void setup() throws IOException {
132-
if (indexExists(CSV_DATASET_MAP.keySet().iterator().next()) == false) {
135+
if (supportsInferenceTestService() && clusterHasInferenceEndpoint(client()) == false) {
136+
createInferenceEndpoint(client());
137+
}
138+
139+
if (indexExists(availableDatasetsForEs(client()).iterator().next().indexName()) == false) {
133140
loadDataSetIntoEs(client());
134141
}
135142
}
@@ -148,6 +155,8 @@ public static void wipeTestData() throws IOException {
148155
throw e;
149156
}
150157
}
158+
159+
deleteInferenceEndpoint(client());
151160
}
152161

153162
public boolean logResults() {
@@ -164,6 +173,9 @@ public final void test() throws Throwable {
164173
}
165174

166175
protected void shouldSkipTest(String testName) throws IOException {
176+
if (testCase.requiredCapabilities.contains("semantic_text_type")) {
177+
assumeTrue("Inference test service needs to be supported for semantic_text", supportsInferenceTestService());
178+
}
167179
checkCapabilities(adminClient(), testFeatureService, testName, testCase);
168180
assumeTrue("Test " + testName + " is not enabled", isEnabled(testName, instructions, Version.CURRENT));
169181
}
@@ -207,6 +219,10 @@ protected static void checkCapabilities(RestClient client, TestFeatureService te
207219
}
208220
}
209221

222+
protected boolean supportsInferenceTestService() {
223+
return true;
224+
}
225+
210226
protected final void doTest() throws Throwable {
211227
RequestObjectBuilder builder = new RequestObjectBuilder(randomFrom(XContentType.values()));
212228

0 commit comments

Comments
 (0)