Java Code Examples for org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder#setSettings()
The following examples show how to use
org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder#setSettings() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ESClient.java From uavstack with Apache License 2.0 | 6 votes |
public boolean creatIndex(String index, String type, Map<String, String> set, Map<String, Map<String, Object>> mapping) throws IOException { CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(index); if (type != null && mapping != null) { createIndexRequestBuilder.addMapping(type, createMapping(type, mapping)); } if (set != null) { createIndexRequestBuilder.setSettings(createSetting(set)); } CreateIndexResponse resp = createIndexRequestBuilder.execute().actionGet(); if (resp.isAcknowledged()) { return true; } return false; }
Example 2
Source File: IndexCreate.java From sfs with Apache License 2.0 | 6 votes |
@Override public Observable<Boolean> call(String index) { Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch(); CreateIndexRequestBuilder request = elasticsearch.get().admin().indices().prepareCreate(index); for (Map.Entry<String, String> entry : mappings.entrySet()) { String type = entry.getKey(); String mapping = entry.getValue(); request = request.addMapping(type, mapping); } if (settings != null) { request.setSettings(settings); } if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Request %s", Jsonify.toString(request))); } return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout()) .map(Optional::get) .doOnNext(createIndexResponse -> { if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Response %s", Jsonify.toString(createIndexResponse))); } }) .map(AcknowledgedResponse::isAcknowledged); }
Example 3
Source File: ElasticsearchClientTransport.java From c2mon with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean createIndex(IndexMetadata indexMetadata, String mapping) { CreateIndexRequestBuilder builder = client.admin().indices().prepareCreate(indexMetadata.getName()); builder.setSettings(Settings.builder() .put("number_of_shards", properties.getShardsPerIndex()) .put("number_of_replicas", properties.getReplicasPerShard()) .build()); if (mapping != null) { builder.addMapping(TYPE, mapping, XContentType.JSON); } log.debug("Creating new index with name {}", indexMetadata.getName()); try { CreateIndexResponse response = builder.get(); return response.isAcknowledged(); } catch (ResourceAlreadyExistsException e) { log.debug("Index already exists.", e); } return false; }
Example 4
Source File: InternalEsClient.java From io with Apache License 2.0 | 6 votes |
/** * インデックスを作成する. * @param index インデックス名 * @param mappings マッピング情報 * @return 非同期応答 */ public ActionFuture<CreateIndexResponse> createIndex(String index, Map<String, JSONObject> mappings) { this.fireEvent(Event.creatingIndex, index); CreateIndexRequestBuilder cirb = new CreateIndexRequestBuilder(esTransportClient.admin().indices(), CreateIndexAction.INSTANCE, index); // cjkアナライザ設定 Settings.Builder indexSettings = Settings.settingsBuilder(); indexSettings.put("analysis.analyzer.default.type", "cjk"); cirb.setSettings(indexSettings); if (mappings != null) { for (Map.Entry<String, JSONObject> ent : mappings.entrySet()) { cirb = cirb.addMapping(ent.getKey(), ent.getValue().toString()); } } return cirb.execute(); }
Example 5
Source File: InternalEsClient.java From io with Apache License 2.0 | 6 votes |
/** * インデックスを作成する. * @param index インデックス名 * @param mappings マッピング情報 * @return 非同期応答 */ public ActionFuture<CreateIndexResponse> createIndex(String index, Map<String, JSONObject> mappings) { this.fireEvent(Event.creatingIndex, index); CreateIndexRequestBuilder cirb = new CreateIndexRequestBuilder(esTransportClient.admin().indices()).setIndex(index); // cjkアナライザ設定 ImmutableSettings.Builder indexSettings = ImmutableSettings.settingsBuilder(); indexSettings.put("analysis.analyzer.default.type", "cjk"); cirb.setSettings(indexSettings); if (mappings != null) { for (Map.Entry<String, JSONObject> ent : mappings.entrySet()) { cirb = cirb.addMapping(ent.getKey(), ent.getValue().toString()); } } return cirb.execute(); }
Example 6
Source File: BaseMetricTransportClient.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
@Override public BaseMetricTransportClient newIndex(String index, Settings settings, Map<String, String> mappings) { if (client == null) { logger.warn("no client for create index"); return this; } if (index == null) { logger.warn("no index name given to create index"); return this; } CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client(), CreateIndexAction.INSTANCE).setIndex(index); if (settings != null) { logger.info("settings = {}", settings.getAsStructuredMap()); createIndexRequestBuilder.setSettings(settings); } if (mappings != null) { for (String type : mappings.keySet()) { logger.info("found mapping for {}", type); createIndexRequestBuilder.addMapping(type, mappings.get(type)); } } createIndexRequestBuilder.execute().actionGet(); logger.info("index {} created", index); return this; }
Example 7
Source File: ESConnector.java From Siamese with GNU General Public License v3.0 | 5 votes |
public boolean createIndex(String indexName, String typeName, String settingsStr, String mappingStr) { CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(indexName); Settings settings = Settings.builder() .loadFromSource(settingsStr) .build(); createIndexRequestBuilder.setSettings(settings); createIndexRequestBuilder.addMapping(typeName, mappingStr); CreateIndexResponse response = createIndexRequestBuilder.execute().actionGet(); return response.isAcknowledged(); }
Example 8
Source File: ElasticsearchClient.java From hawkular-apm with Apache License 2.0 | 5 votes |
/** * Check if index is created. if not it will created it * * @param index The index * @return returns true if it just created the index. False if the index already existed */ private boolean createIndex(String index, Map<String, Object> defaultSettings) { IndicesExistsResponse res = client.admin().indices().prepareExists(index).execute().actionGet(); boolean created = false; if (!res.isExists()) { CreateIndexRequestBuilder req = client.admin().indices().prepareCreate(index); req.setSettings(defaultSettings); created = req.execute().actionGet().isAcknowledged(); if (!created) { throw new RuntimeException("Could not create index [" + index + "]"); } } return created; }
Example 9
Source File: BulkNodeClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override public BulkNodeClient newIndex(String index, Settings settings, Map<String, String> mappings) { if (closed) { throw new ElasticsearchException("client is closed"); } if (client == null) { logger.warn("no client for create index"); return this; } if (index == null) { logger.warn("no index name given to create index"); return this; } CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client(), CreateIndexAction.INSTANCE).setIndex(index); if (settings != null) { logger.info("settings = {}", settings.getAsStructuredMap()); createIndexRequestBuilder.setSettings(settings); } if (mappings != null) { for (String type : mappings.keySet()) { logger.info("found mapping for {}", type); createIndexRequestBuilder.addMapping(type, mappings.get(type)); } } createIndexRequestBuilder.execute().actionGet(); logger.info("index {} created", index); return this; }
Example 10
Source File: HttpBulkNodeClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
@Override public HttpBulkNodeClient newIndex(String index, Settings settings, Map<String, String> mappings) { if (closed) { throw new ElasticsearchException("client is closed"); } if (client == null) { logger.warn("no client for create index"); return this; } if (index == null) { logger.warn("no index name given to create index"); return this; } CreateIndexRequestBuilder createIndexRequestBuilder = new CreateIndexRequestBuilder(client(), CreateIndexAction.INSTANCE).setIndex(index); if (settings != null) { logger.info("settings = {}", settings.getAsStructuredMap()); createIndexRequestBuilder.setSettings(settings); } if (mappings != null) { for (String type : mappings.keySet()) { logger.info("found mapping for {}", type); createIndexRequestBuilder.addMapping(type, mappings.get(type)); } } createIndexRequestBuilder.execute().actionGet(); logger.info("index {} created", index); return this; }
Example 11
Source File: ElasticsearchMailDestination.java From elasticsearch-imap with Apache License 2.0 | 4 votes |
private synchronized void createIndexIfNotExists() throws IOException { if (isError()) { if (logger.isTraceEnabled()) { logger.trace("error, not creating index"); } return; } if(initialized) { return; } IMAPImporter.waitForYellowCluster(client); // create index if it doesn't already exist if (!client.admin().indices().prepareExists(index).execute().actionGet().isExists()) { final CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate(index); if (settings != null) { logger.debug("index settings are provided, will apply them {}", settings); createIndexRequestBuilder.setSettings(settings); } else { logger.debug("no settings given for index '{}'",index); } if (mapping != null) { logger.warn("mapping for type '{}' is provided, will apply {}", type, mapping); createIndexRequestBuilder.addMapping(type, mapping); } else { logger.debug("no mapping given for type '{}', will apply default mapping",type); createIndexRequestBuilder.addMapping(type, getDefaultTypeMapping()); } final CreateIndexResponse res = createIndexRequestBuilder.get(); if (!res.isAcknowledged()) { throw new IOException("Could not create index " + index); } IMAPImporter.waitForYellowCluster(client); logger.info("Index {} created", index); } else { logger.debug("Index {} already exists", index); } initialized = true; }