99
1010import com .carrotsearch .randomizedtesting .annotations .ParametersFactory ;
1111import com .carrotsearch .randomizedtesting .annotations .ThreadLeakFilters ;
12- import com .carrotsearch .randomizedtesting .annotations .TimeoutSuite ;
1312
14- import org .apache .lucene .tests .util .TimeUnits ;
1513import org .elasticsearch .client .Request ;
1614import org .elasticsearch .client .Response ;
1715import org .elasticsearch .client .ResponseException ;
2523import org .elasticsearch .xpack .esql .AssertWarnings ;
2624import org .elasticsearch .xpack .esql .qa .rest .RestEsqlTestCase ;
2725import org .hamcrest .Matcher ;
26+ import org .junit .Before ;
2827import org .junit .ClassRule ;
2928
3029import java .io .IOException ;
5150 * Tests for pushing queries to lucene.
5251 */
5352@ ThreadLeakFilters (filters = TestClustersThreadFilter .class )
54- @ TimeoutSuite (millis = 10 * TimeUnits .MINUTE ) // semantic_text can take a long, long time to start in CI
5553public class PushQueriesIT extends ESRestTestCase {
5654 @ ClassRule
57- public static ElasticsearchCluster cluster = Clusters .testCluster ();
55+ public static ElasticsearchCluster cluster = Clusters .testCluster (spec -> spec . plugin ( "inference-service-test" ) );
5856
5957 @ ParametersFactory (argumentFormatting = "%1s" )
6058 public static List <Object []> args () {
@@ -288,13 +286,30 @@ private void indexValue(String value) throws IOException {
288286 "number_of_shards": 1
289287 }
290288 }""" ;
291- if (false == "auto" .equals (type )) {
292- json += """
289+ json += switch (type ) {
290+ case "auto" -> "" ;
291+ case "semantic_text" -> """
293292 ,
294293 "mappings": {
295294 "properties": {
296295 "test": {
297- "type": "%type",
296+ "type": "semantic_text",
297+ "inference_id": "test",
298+ "fields": {
299+ "keyword": {
300+ "type": "keyword",
301+ "ignore_above": 256
302+ }
303+ }
304+ }
305+ }
306+ }""" ;
307+ default -> """
308+ ,
309+ "mappings": {
310+ "properties": {
311+ "test": {
312+ "type": "%type",
298313 "fields": {
299314 "keyword": {
300315 "type": "keyword",
@@ -305,7 +320,7 @@ private void indexValue(String value) throws IOException {
305320 }
306321 }
307322 }""" .replace ("%type" , type );
308- }
323+ };
309324 json += "}" ;
310325 createIndex .setJsonEntity (json );
311326 Response createResponse = client ().performRequest (createIndex );
@@ -347,4 +362,28 @@ protected boolean preserveClusterUponCompletion() {
347362 // Preserve the cluser to speed up the semantic_text tests
348363 return true ;
349364 }
365+
366+ private static boolean setupEmbeddings = false ;
367+
368+ @ Before
369+ public void setUpTextEmbeddingInferenceEndpoint () throws IOException {
370+ if (type .equals ("semantic_text" ) == false || setupEmbeddings ) {
371+ return ;
372+ }
373+ setupEmbeddings = true ;
374+ Request request = new Request ("PUT" , "_inference/text_embedding/test" );
375+ request .setJsonEntity ("""
376+ {
377+ "service": "text_embedding_test_service",
378+ "service_settings": {
379+ "model": "my_model",
380+ "api_key": "abc64",
381+ "dimensions": 128
382+ },
383+ "task_settings": {
384+ }
385+ }
386+ """ );
387+ adminClient ().performRequest (request );
388+ }
350389}
0 commit comments