9
9
10
10
import com .carrotsearch .randomizedtesting .annotations .ParametersFactory ;
11
11
import com .carrotsearch .randomizedtesting .annotations .ThreadLeakFilters ;
12
- import com .carrotsearch .randomizedtesting .annotations .TimeoutSuite ;
13
12
14
- import org .apache .lucene .tests .util .TimeUnits ;
15
13
import org .elasticsearch .client .Request ;
16
14
import org .elasticsearch .client .Response ;
17
15
import org .elasticsearch .client .ResponseException ;
25
23
import org .elasticsearch .xpack .esql .AssertWarnings ;
26
24
import org .elasticsearch .xpack .esql .qa .rest .RestEsqlTestCase ;
27
25
import org .hamcrest .Matcher ;
26
+ import org .junit .Before ;
28
27
import org .junit .ClassRule ;
29
28
30
29
import java .io .IOException ;
51
50
* Tests for pushing queries to lucene.
52
51
*/
53
52
@ ThreadLeakFilters (filters = TestClustersThreadFilter .class )
54
- @ TimeoutSuite (millis = 10 * TimeUnits .MINUTE ) // semantic_text can take a long, long time to start in CI
55
53
public class PushQueriesIT extends ESRestTestCase {
56
54
@ ClassRule
57
- public static ElasticsearchCluster cluster = Clusters .testCluster ();
55
+ public static ElasticsearchCluster cluster = Clusters .testCluster (spec -> spec . plugin ( "inference-service-test" ) );
58
56
59
57
@ ParametersFactory (argumentFormatting = "%1s" )
60
58
public static List <Object []> args () {
@@ -288,13 +286,30 @@ private void indexValue(String value) throws IOException {
288
286
"number_of_shards": 1
289
287
}
290
288
}""" ;
291
- if (false == "auto" .equals (type )) {
292
- json += """
289
+ json += switch (type ) {
290
+ case "auto" -> "" ;
291
+ case "semantic_text" -> """
293
292
,
294
293
"mappings": {
295
294
"properties": {
296
295
"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",
298
313
"fields": {
299
314
"keyword": {
300
315
"type": "keyword",
@@ -305,7 +320,7 @@ private void indexValue(String value) throws IOException {
305
320
}
306
321
}
307
322
}""" .replace ("%type" , type );
308
- }
323
+ };
309
324
json += "}" ;
310
325
createIndex .setJsonEntity (json );
311
326
Response createResponse = client ().performRequest (createIndex );
@@ -347,4 +362,28 @@ protected boolean preserveClusterUponCompletion() {
347
362
// Preserve the cluser to speed up the semantic_text tests
348
363
return true ;
349
364
}
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
+ }
350
389
}
0 commit comments