|
11 | 11 | import org.elasticsearch.cluster.metadata.AliasMetadata;
|
12 | 12 | import org.elasticsearch.cluster.metadata.IndexMetadata;
|
13 | 13 | import org.elasticsearch.cluster.metadata.Metadata;
|
| 14 | +import org.elasticsearch.index.IndexNotFoundException; |
14 | 15 | import org.elasticsearch.index.query.MatchQueryBuilder;
|
15 | 16 | import org.elasticsearch.search.builder.SearchSourceBuilder;
|
16 | 17 | import org.elasticsearch.test.ESTestCase;
|
|
24 | 25 | import java.util.Map;
|
25 | 26 |
|
26 | 27 | import static org.elasticsearch.xpack.enrich.MatchProcessorTests.mapOf;
|
| 28 | +import static org.hamcrest.Matchers.containsString; |
27 | 29 | import static org.hamcrest.Matchers.equalTo;
|
28 | 30 | import static org.hamcrest.Matchers.not;
|
29 | 31 | import static org.hamcrest.Matchers.notNullValue;
|
@@ -186,4 +188,22 @@ public void testDeepCopy() {
|
186 | 188 | assertArrayEquals(new byte[] { 1, 2, 3 }, (byte[]) result.get("embedded_object"));
|
187 | 189 | }
|
188 | 190 |
|
| 191 | + public void testEnrichIndexNotExist() { |
| 192 | + // Emulate cluster metadata: |
| 193 | + Metadata metadata = Metadata.builder().build(); |
| 194 | + |
| 195 | + // Emulated search request on a non-exist enrich index that an enrich processor could generate |
| 196 | + SearchRequest searchRequest = new SearchRequest(EnrichPolicy.getBaseName("policy-enrich-index-not-generated")).source( |
| 197 | + new SearchSourceBuilder().query(new MatchQueryBuilder("test", "query")) |
| 198 | + ); |
| 199 | + // Emulated search response (content doesn't matter, since it isn't used, it just a cache entry) |
| 200 | + List<Map<?, ?>> searchResponse = Collections.singletonList(Collections.singletonMap("test", "entry")); |
| 201 | + |
| 202 | + EnrichCache enrichCache = new EnrichCache(1); |
| 203 | + enrichCache.setMetadata(metadata); |
| 204 | + |
| 205 | + IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> enrichCache.put(searchRequest, searchResponse)); |
| 206 | + assertThat(e.getMessage(), containsString("no generated enrich index [.enrich-policy-enrich-index-not-generated]")); |
| 207 | + } |
| 208 | + |
189 | 209 | }
|
0 commit comments