@Test public void get_with_string_timeout_is_not_yet_implemented() { try { es.client().prepareCreate(generateNewIndexName()).get("1"); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
@Test public void get_with_time_value_timeout_is_not_yet_implemented() { try { es.client().prepareCreate(generateNewIndexName()).get(TimeValue.timeValueMinutes(1)); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
.prepareCreate(index.getName()) .setSettings(settings) .get(); if (!indexResponse.isAcknowledged()) { throw new IllegalStateException("Failed to create index " + index.getName());
@Test public void trace_logs() { logTester.setLevel(LoggerLevel.TRACE); CreateIndexRequestBuilder requestBuilder = es.client().prepareCreate(generateNewIndexName()); requestBuilder.get(); assertThat(logTester.logs()).hasSize(1); }
@Test public void create_index() { CreateIndexRequestBuilder requestBuilder = es.client().prepareCreate(generateNewIndexName()); requestBuilder.get(); }
.prepareCreate(index.getName()) .setSettings(settings) .get(); if (!indexResponse.isAcknowledged()) { throw new IllegalStateException("Failed to create index " + index.getName());
esClient.admin().indices().prepareCreate(definition.getIndexName()).get();
public void createIndexWithMapping(String indexName, String mappingType, String mappingSource) throws IOException { CreateIndexResponse cir = client.admin().indices().prepareCreate(indexName) .addMapping(mappingType, mappingSource) .get(); if (!cir.isAcknowledged()) { throw new IOException("Create index was not acknowledged"); } }
for(Mapping m : Optional.ofNullable(mappings).orElse(new ArrayList<>())) { client.admin().indices().prepareCreate(m.index) .addMapping(m.docType, m.mapping).get();
@Override public void createIndex(String indexName, String jsonSettings) { client.admin().indices().prepareCreate(indexName).setSettings(jsonSettings, XContentType.JSON).get(); }
/** * Initialize the index in the Elasticsearch cluster with the current settings. */ @PostConstruct public void initializeIndex() { if (!this.client.admin().indices().prepareExists(index).get().isExists()) { this.client.admin().indices().prepareCreate(index).setSource(settings).get(); } }
@VisibleForTesting protected String createIndex() { final String indexName = this.configuration.getAlias() + "_" + System.currentTimeMillis(); CreateIndexRequestBuilder prepareCreate = this.client.admin().indices() .prepareCreate(indexName); if (this.configuration.getSource() != null) { try { prepareCreate .setSource(ByteStreams.toByteArray(this.configuration.getSource().getInputStream())); } catch (IOException e) { logger.error("Can't read index {} configuration file {}", indexName, this.configuration.getSource(), e); } } CreateIndexResponse createIndexResponse = prepareCreate.get(); if (!createIndexResponse.isAcknowledged()) { throw new IllegalStateException("Error creating index for Lotus BO"); } return indexName; }
/** * Create the .zentity-models index. * * @param client The client that will communicate with Elasticsearch. * @param numberOfShards The value of index.number_of_shards. * @param numberOfReplicas The value of index.number_of_replicas. * @return */ public static CreateIndexResponse createIndex(NodeClient client, int numberOfShards, int numberOfReplicas) { return client.admin().indices().prepareCreate(ModelsAction.INDEX_NAME) .setSettings(Settings.builder() .put("index.number_of_shards", numberOfShards) .put("index.number_of_replicas", numberOfReplicas) ) .addMapping("doc", INDEX_MAPPING, XContentType.JSON) .get(); }
@Override public void createIndex(String index) { log.debug("Create index in ElasticSearch [index: {}]", index); // Validation if (StringUtils.isEmpty(index)) throw new IllegalArgumentException("index " + ERROR_NOT_NULL_OR_EMPTY); try { // Check existence boolean exists = client.admin().indices().prepareExists(formatIndex(Optional.of(index))).execute().actionGet() .isExists(); if (!exists) { client.admin().indices().prepareCreate(formatIndex(Optional.of(index))).get(); log.debug("Index [index: {}] created in ElasticSearch", index); } else { log.debug("Index [index: {}] already exists in ElasticSearch", index); } } catch (Exception ex) { log.error("Error while creating the index [index: {}] into ElasticSearch", index, ex); throw new TechnicalException( "Error while creating the index into ElasticSearch: " + ex.getMessage()); } }
@Override public void run() { try { client.admin().indices().prepareCreate(config.getIndexName()).get(); } catch (Exception e) { if (ExceptionsHelper.unwrapCause(e) instanceof IndexAlreadyExistsException) { logger.info("index [{}] already exists", e, config.getIndexName()); } else if (ExceptionsHelper.unwrapCause(e) instanceof ClusterBlockException) { logger.info("cluster block exception for index [{}]", e, config.getIndexName()); } else { logger.error("failed to create index [{}], disabling river...", e, config.getIndexName()); // TODO: shouldn't we throw some exception to let ES know an error has happened? return; } } walReaderThread = walReaderThreadFactory.newThread(walReaderRunnable); walReaderThread.start(); indexWriterThread = indexWriterThreadFactory.newThread(indexWriterRunnable); indexWriterThread.start(); logger.info("started arangodb river"); } }.start();
@Test public void testUkrainianAnalyzerInMapping() throws IOException { final XContentBuilder mapping = jsonBuilder().startObject() .startObject("type") .startObject("properties") .startObject("foo") .field("type", "string") .field("analyzer", "ukrainian") .endObject() .endObject() .endObject() .endObject(); client().admin().indices().prepareCreate("test").addMapping("type", mapping).get(); index("test", "type", "1", "foo", "б'ючи іменинника"); ensureYellow(); }
public void putMapping(String index, String type, MetaObject metaObject) { checkNotEmpty("index", index); checkNotEmpty("type", type); checkNotNull("metaObject", metaObject); try { this.getClient().admin().indices().prepareCreate(sanitizeIndex(index)).get(); } catch (ResourceAlreadyExistsException ex) { logger.debug("Resource Already exists: " + ex.getMessage()); } Map<String, Object> properties = this.createMappingMap(metaObject.getProperties()); this.getClient().admin().indices() .preparePutMapping(sanitizeIndex(index)) .setType(sanitizeIndex(type)) .setSource(properties).get(); }
public void putMapping(String index, String type, MetaObject metaObject) { checkNotEmpty("index", index); checkNotEmpty("type", type); checkNotNull("metaObject", metaObject); try { this.getClient().admin().indices().prepareCreate(sanitizeIndex(index)).get(); } catch (ResourceAlreadyExistsException ex) { logger.debug("Resource Already exists: " + ex.getMessage()); } Map<String, Object> properties = this.createMappingMap(metaObject.getProperties()); this.getClient().admin().indices() .preparePutMapping(sanitizeIndex(index)) .setType(sanitizeIndex(type)) .setSource(properties).get(); }
/** * Register the siren field */ protected void init() throws IOException { XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .startObject("json") .startObject("properties") .startObject("_siren_source") .field("analyzer", "concise") .field("postings_format", "Siren10AFor") .field("store", "no") .field("type", "string") .endObject() .endObject() .startObject("_siren") .endObject() .endObject() .endObject(); prepareCreate(INDEX_NAME).addMapping("json", builder).get(); ensureGreen(); }
protected IndexService createIndex(String index, CreateIndexRequestBuilder createIndexRequestBuilder) { assertAcked(createIndexRequestBuilder.get()); // Wait for the index to be allocated so that cluster state updates don't override // changes that would have been done locally ClusterHealthRequestBuilder builder = client().admin().cluster().prepareHealth(index); builder.setWaitForYellowStatus() .setWaitForEvents(Priority.LANGUID) .setWaitForNoRelocatingShards(true); ClusterHealthResponse health = builder.get(); assertThat(health.getStatus(), lessThanOrEqualTo(ClusterHealthStatus.YELLOW)); assertThat("Cluster must be a single node cluster", health.getNumberOfDataNodes(), equalTo(1)); IndicesService instanceFromNode = getInstanceFromNode(IndicesService.class); return instanceFromNode.indexServiceSafe(resolveIndex(index)); }