ElasticsearchIndexer implements Indexer { @Override public String executeRaw(String method, String url, String rawJson) throws IOException { Request request = new Request(method, url.startsWith("/")? url: "/" + url); if (rawJson != null && !rawJson.isEmpty()) { request.setJsonEntity(rawJson); } Response response = client.getLowLevelClient().performRequest(request); if ("OPTIONS".equals(method)) { return response.getHeader("Allow"); } HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity):null; } @Inject  ElasticsearchIndexer(final RestHighLevelClient esClient, final PropertiesProvider propertiesProvider); @Override void close(); @Override boolean bulkAdd(final String indexName, Pipeline.Type nerType, List<NamedEntity> namedEntities, Document parent); @Override boolean bulkUpdate(String indexName, List<? extends Entity> entities); @Override void add(final String indexName, T obj); @Override void update(String indexName, T obj); @Override String executeRaw(String method, String url, String rawJson); T get(String indexName, String id); @Override T get(String indexName, String id, String root); @Override boolean tag(Project prj, String documentId, String rootDocument, Tag... tags); @Override boolean untag(Project prj, String documentId, String rootDocument, Tag... tags); @Override boolean tag(Project prj, List<String> documentIds, Tag... tags); @Override boolean untag(Project prj, List<String> documentIds, Tag... tags); @Override Searcher search(final String indexName, Class<? extends Entity> entityClass); @Override boolean createIndex(final String indexName); @Override boolean deleteAll(String indexName); ElasticsearchIndexer withRefresh(WriteRequest.RefreshPolicy refresh); @Override boolean getHealth(); final RestHighLevelClient client; }
@Test public void test_execute_raw_with_head() throws Exception { assertThat(indexer.executeRaw("HEAD", TEST_INDEX, "")).isNull(); assertThat(indexer.executeRaw("HEAD", TEST_INDEX, null)).isNull(); }
@Test public void test_execute_raw_with_options() throws Exception { assertThat(indexer.executeRaw("OPTIONS", TEST_INDEX, "").split(",")).containsOnly("PUT","HEAD","DELETE","GET"); assertThat(indexer.executeRaw("OPTIONS", TEST_INDEX, null).split(",")).containsOnly("PUT","HEAD","DELETE","GET"); }