Indexer { public void prepareIndex() throws IOException { boolean indexExists = client.admin().indices().prepareExists(INDEX).execute().actionGet().isExists(); if (indexExists) { client.admin().indices().prepareDelete(INDEX).execute().actionGet(); } client.admin().indices().prepareCreate(INDEX).execute().actionGet(); XContentBuilder builder = XContentFactory.jsonBuilder(). startObject(). startObject(TYPE). startObject("properties"). startObject("path").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject(). startObject("title").field("type", "string").field("store", "yes").field("analyzer", "german").endObject(). startObject("category").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject(). startObject("speaker").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject(). startObject("date").field("type", "date").field("store", "yes").field("index", "not_analyzed").endObject(). startObject("content").field("type", "string").field("store", "yes").field("analyzer", "german").field("term_vector", "with_positions_offsets").endObject(). startObject("organizer").field("type", "string").field("store", "yes").field("index", "not_analyzed").endObject(). endObject(). endObject(). endObject(); client.admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(builder).execute().actionGet(); } Indexer(Client client); void index(Collection<Talk> talks); void prepareIndex(); static void main(String[] args);  }
@Test public void prepareIndexCreatesIndex() throws IOException { assertFalse(indexExists(Indexer.INDEX)); indexer.prepareIndex(); assertTrue(indexExists(Indexer.INDEX)); }