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 ;
52
51
* Tests for pushing queries to lucene.
53
52
*/
54
53
@ ThreadLeakFilters (filters = TestClustersThreadFilter .class )
55
- @ TimeoutSuite (millis = 10 * TimeUnits .MINUTE ) // semantic_text can take a long, long time to start in CI
56
54
public class PushQueriesIT extends ESRestTestCase {
57
55
@ ClassRule
58
- public static ElasticsearchCluster cluster = Clusters .testCluster ();
56
+ public static ElasticsearchCluster cluster = Clusters .testCluster (spec -> spec . plugin ( "inference-service-test" ) );
59
57
60
58
@ ParametersFactory (argumentFormatting = "%1s" )
61
59
public static List <Object []> args () {
@@ -294,13 +292,30 @@ private void indexValue(String value) throws IOException {
294
292
"number_of_shards": 1
295
293
}
296
294
}""" ;
297
- if (false == "auto" .equals (type )) {
298
- json += """
295
+ json += switch (type ) {
296
+ case "auto" -> "" ;
297
+ case "semantic_text" -> """
299
298
,
300
299
"mappings": {
301
300
"properties": {
302
301
"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",
304
319
"fields": {
305
320
"keyword": {
306
321
"type": "keyword",
@@ -311,7 +326,7 @@ private void indexValue(String value) throws IOException {
311
326
}
312
327
}
313
328
}""" .replace ("%type" , type );
314
- }
329
+ };
315
330
json += "}" ;
316
331
createIndex .setJsonEntity (json );
317
332
Response createResponse = client ().performRequest (createIndex );
@@ -353,4 +368,28 @@ protected boolean preserveClusterUponCompletion() {
353
368
// Preserve the cluser to speed up the semantic_text tests
354
369
return true ;
355
370
}
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
+ }
356
395
}
0 commit comments