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 ;
5251 * Tests for pushing queries to lucene.
5352 */
5453@ ThreadLeakFilters (filters = TestClustersThreadFilter .class )
55- @ TimeoutSuite (millis = 10 * TimeUnits .MINUTE ) // semantic_text can take a long, long time to start in CI
5654public class PushQueriesIT extends ESRestTestCase {
5755 @ ClassRule
58- public static ElasticsearchCluster cluster = Clusters .testCluster ();
56+ public static ElasticsearchCluster cluster = Clusters .testCluster (spec -> spec . plugin ( "inference-service-test" ) );
5957
6058 @ ParametersFactory (argumentFormatting = "%1s" )
6159 public static List <Object []> args () {
@@ -294,13 +292,30 @@ private void indexValue(String value) throws IOException {
294292 "number_of_shards": 1
295293 }
296294 }""" ;
297- if (false == "auto" .equals (type )) {
298- json += """
295+ json += switch (type ) {
296+ case "auto" -> "" ;
297+ case "semantic_text" -> """
299298 ,
300299 "mappings": {
301300 "properties": {
302301 "test": {
303- "type": "%type",
302+ "type": "semantic_text",
303+ "inference_id": "test",
304+ "fields": {
305+ "keyword": {
306+ "type": "keyword",
307+ "ignore_above": 256
308+ }
309+ }
310+ }
311+ }
312+ }""" ;
313+ default -> """
314+ ,
315+ "mappings": {
316+ "properties": {
317+ "test": {
318+ "type": "%type",
304319 "fields": {
305320 "keyword": {
306321 "type": "keyword",
@@ -311,7 +326,7 @@ private void indexValue(String value) throws IOException {
311326 }
312327 }
313328 }""" .replace ("%type" , type );
314- }
329+ };
315330 json += "}" ;
316331 createIndex .setJsonEntity (json );
317332 Response createResponse = client ().performRequest (createIndex );
@@ -353,4 +368,28 @@ protected boolean preserveClusterUponCompletion() {
353368 // Preserve the cluser to speed up the semantic_text tests
354369 return true ;
355370 }
371+
372+ private static boolean setupEmbeddings = false ;
373+
374+ @ Before
375+ public void setUpTextEmbeddingInferenceEndpoint () throws IOException {
376+ if (type .equals ("semantic_text" ) == false || setupEmbeddings ) {
377+ return ;
378+ }
379+ setupEmbeddings = true ;
380+ Request request = new Request ("PUT" , "_inference/text_embedding/test" );
381+ request .setJsonEntity ("""
382+ {
383+ "service": "text_embedding_test_service",
384+ "service_settings": {
385+ "model": "my_model",
386+ "api_key": "abc64",
387+ "dimensions": 128
388+ },
389+ "task_settings": {
390+ }
391+ }
392+ """ );
393+ adminClient ().performRequest (request );
394+ }
356395}
0 commit comments