@Override public boolean createIndex(String indexName) { Assert.notNull(indexName, "No index defined for Query"); return client .admin() .indices() .create(Requests.createIndexRequest(indexName)) .actionGet() .isAcknowledged(); }
@Test public void testCopyHeadersIndicesAdminRequest() { Map<String, String> transportHeaders = randomHeaders(randomIntBetween(0, 10)); Map<String, String> restHeaders = randomHeaders(randomIntBetween(0, 10)); Map<String, String> copiedHeaders = randomHeadersFrom(restHeaders); Set<String> usefulRestHeaders = new HashSet<>(copiedHeaders.keySet()); usefulRestHeaders.addAll(randomMap(randomIntBetween(0, 10), "useful-").keySet()); Map<String, String> restContext = randomContext(randomIntBetween(0, 10)); Map<String, String> transportContext = Maps.difference(randomContext(randomIntBetween(0, 10)), restContext).entriesOnlyOnLeft(); HashMap<String, String> expectedHeaders = new HashMap<>(); expectedHeaders.putAll(transportHeaders); expectedHeaders.putAll(copiedHeaders); Map<String, String> expectedContext = new HashMap<>(); expectedContext.putAll(transportContext); expectedContext.putAll(restContext); Client client = client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders); CreateIndexRequest createIndexRequest = Requests.createIndexRequest("test"); putHeaders(createIndexRequest, transportHeaders); putContext(createIndexRequest, transportContext); assertHeaders(createIndexRequest, transportHeaders); client.admin().indices().create(createIndexRequest); assertHeaders(createIndexRequest, expectedHeaders); assertContext(createIndexRequest, expectedContext); CloseIndexRequest closeIndexRequest = Requests.closeIndexRequest("test"); putHeaders(closeIndexRequest, transportHeaders); putContext(closeIndexRequest, transportContext); assertHeaders(closeIndexRequest, transportHeaders); client.admin().indices().close(closeIndexRequest); assertHeaders(closeIndexRequest, expectedHeaders); assertContext(closeIndexRequest, expectedContext); FlushRequest flushRequest = Requests.flushRequest(); putHeaders(flushRequest, transportHeaders); putContext(flushRequest, transportContext); assertHeaders(flushRequest, transportHeaders); client.admin().indices().flush(flushRequest); assertHeaders(flushRequest, expectedHeaders); assertContext(flushRequest, expectedContext); }