|
53 | 53 | import java.util.Set; |
54 | 54 | import java.util.concurrent.ExecutionException; |
55 | 55 |
|
| 56 | +import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_HIDDEN_SETTING; |
56 | 57 | import static org.elasticsearch.xpack.inference.Utils.TIMEOUT; |
57 | 58 | import static org.hamcrest.Matchers.equalTo; |
58 | 59 | import static org.hamcrest.Matchers.hasSize; |
@@ -373,6 +374,42 @@ public void testShouldExcludeSystemIndexFields() throws Exception { |
373 | 374 | new InferenceFieldMetadata("semantic-3", "endpoint-002", new String[0], null) |
374 | 375 | ) |
375 | 376 | ), |
| 377 | + Set.of("index_2"), |
| 378 | + Set.of() |
| 379 | + ); |
| 380 | + |
| 381 | + XContentSource response = executeAction(); |
| 382 | + |
| 383 | + assertThat(response.getValue("models"), hasSize(7)); |
| 384 | + assertStats(response, 0, new ModelStats("_all", TaskType.CHAT_COMPLETION, 0, new SemanticTextStats())); |
| 385 | + assertStats(response, 1, new ModelStats("_all", TaskType.COMPLETION, 0, new SemanticTextStats())); |
| 386 | + assertStats(response, 2, new ModelStats("_all", TaskType.RERANK, 0, new SemanticTextStats())); |
| 387 | + assertStats(response, 3, new ModelStats("_all", TaskType.SPARSE_EMBEDDING, 0, new SemanticTextStats())); |
| 388 | + assertStats(response, 4, new ModelStats("_all", TaskType.TEXT_EMBEDDING, 2, new SemanticTextStats(2, 1, 2))); |
| 389 | + assertStats(response, 5, new ModelStats("eis", TaskType.TEXT_EMBEDDING, 1, new SemanticTextStats(1, 1, 1))); |
| 390 | + assertStats(response, 6, new ModelStats("openai", TaskType.TEXT_EMBEDDING, 1, new SemanticTextStats(1, 1, 1))); |
| 391 | + } |
| 392 | + |
| 393 | + public void testShouldExcludeHiddenIndexFields() throws Exception { |
| 394 | + givenInferenceEndpoints( |
| 395 | + new ModelConfigurations("endpoint-001", TaskType.TEXT_EMBEDDING, "eis", mockServiceSettings("some-model")), |
| 396 | + new ModelConfigurations("endpoint-002", TaskType.TEXT_EMBEDDING, "openai", mockServiceSettings("some-model")) |
| 397 | + ); |
| 398 | + givenInferenceFields( |
| 399 | + Map.of( |
| 400 | + "index_1", |
| 401 | + List.of( |
| 402 | + new InferenceFieldMetadata("semantic-1", "endpoint-001", new String[0], null), |
| 403 | + new InferenceFieldMetadata("semantic-2", "endpoint-002", new String[0], null) |
| 404 | + ), |
| 405 | + "index_2", |
| 406 | + List.of( |
| 407 | + new InferenceFieldMetadata("semantic-1", "endpoint-001", new String[0], null), |
| 408 | + new InferenceFieldMetadata("semantic-2", "endpoint-002", new String[0], null), |
| 409 | + new InferenceFieldMetadata("semantic-3", "endpoint-002", new String[0], null) |
| 410 | + ) |
| 411 | + ), |
| 412 | + Set.of(), |
376 | 413 | Set.of("index_2") |
377 | 414 | ); |
378 | 415 |
|
@@ -425,15 +462,22 @@ private void givenInferenceEndpoints(ModelConfigurations... endpoints) { |
425 | 462 | } |
426 | 463 |
|
427 | 464 | private void givenInferenceFields(Map<String, List<InferenceFieldMetadata>> inferenceFieldsByIndex) { |
428 | | - givenInferenceFields(inferenceFieldsByIndex, Set.of()); |
| 465 | + givenInferenceFields(inferenceFieldsByIndex, Set.of(), Set.of()); |
429 | 466 | } |
430 | 467 |
|
431 | | - private void givenInferenceFields(Map<String, List<InferenceFieldMetadata>> inferenceFieldsByIndex, Set<String> systemIndices) { |
| 468 | + private void givenInferenceFields( |
| 469 | + Map<String, List<InferenceFieldMetadata>> inferenceFieldsByIndex, |
| 470 | + Set<String> systemIndices, |
| 471 | + Set<String> hiddenIndices |
| 472 | + ) { |
432 | 473 | Map<String, IndexMetadata> indices = new HashMap<>(); |
433 | 474 | for (Map.Entry<String, List<InferenceFieldMetadata>> entry : inferenceFieldsByIndex.entrySet()) { |
434 | 475 | String index = entry.getKey(); |
435 | 476 | IndexMetadata.Builder indexMetadata = IndexMetadata.builder(index) |
436 | | - .settings(ESTestCase.settings(IndexVersion.current())) |
| 477 | + .settings( |
| 478 | + ESTestCase.settings(IndexVersion.current()) |
| 479 | + .put(INDEX_HIDDEN_SETTING.getKey(), hiddenIndices.contains(index) ? "true" : "false") |
| 480 | + ) |
437 | 481 | .numberOfShards(randomIntBetween(1, 5)) |
438 | 482 | .system(systemIndices.contains(index)) |
439 | 483 | .numberOfReplicas(1); |
|
0 commit comments