Java Code Examples for org.elasticsearch.client.indices.CreateIndexRequest#settings()
The following examples show how to use
org.elasticsearch.client.indices.CreateIndexRequest#settings() .
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: BaseElasticsearchService.java From spring-boot-demo with MIT License | 5 votes |
/** * create elasticsearch index (asyc) * * @param index elasticsearch index * @author fxbin */ protected void createIndexRequest(String index) { try { CreateIndexRequest request = new CreateIndexRequest(index); // Settings for this index request.settings(Settings.builder().put("index.number_of_shards", elasticsearchProperties.getIndex().getNumberOfShards()).put("index.number_of_replicas", elasticsearchProperties.getIndex().getNumberOfReplicas())); CreateIndexResponse createIndexResponse = client.indices().create(request, COMMON_OPTIONS); log.info(" whether all of the nodes have acknowledged the request : {}", createIndexResponse.isAcknowledged()); log.info(" Indicates whether the requisite number of shard copies were started for each shard in the index before timing out :{}", createIndexResponse.isShardsAcknowledged()); } catch (IOException e) { throw new ElasticsearchException("创建索引 {" + index + "} 失败"); } }
Example 2
Source File: ElasticSearch7Client.java From skywalking with Apache License 2.0 | 5 votes |
public boolean createIndex(String indexName, Map<String, Object> settings, Map<String, Object> mapping) throws IOException { indexName = formatIndexName(indexName); CreateIndexRequest request = new CreateIndexRequest(indexName); request.settings(settings); request.mapping(mapping); CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT); log.debug("create {} index finished, isAcknowledged: {}", indexName, response.isAcknowledged()); return response.isAcknowledged(); }
Example 3
Source File: CaseController.java From skywalking with Apache License 2.0 | 5 votes |
private void createIndex(String indexName) throws IOException { CreateIndexRequest request = new CreateIndexRequest(indexName); XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); { builder.startObject("properties"); { builder.startObject("author"); { builder.field("type", "keyword"); } builder.endObject(); builder.startObject("title"); { builder.field("type", "keyword"); } builder.endObject(); } builder.endObject(); } builder.endObject(); request.mapping(builder); request.settings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)); CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); if (createIndexResponse.isAcknowledged() == false) { String message = "elasticsearch create index fail."; logger.error(message); throw new RuntimeException(message); } }
Example 4
Source File: RestHighLevelClientCase.java From skywalking with Apache License 2.0 | 5 votes |
private void createIndex(RestHighLevelClient client, String indexName) throws IOException { CreateIndexRequest request = new CreateIndexRequest(indexName); XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); { builder.startObject("properties"); { builder.startObject("author"); { builder.field("type", "keyword"); } builder.endObject(); builder.startObject("title"); { builder.field("type", "keyword"); } builder.endObject(); } builder.endObject(); } builder.endObject(); request.mapping(builder); request.settings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)); CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); if (createIndexResponse.isAcknowledged() == false) { String message = "elasticsearch create index fail."; logger.error(message); throw new RuntimeException(message); } }
Example 5
Source File: ElasticRequestUtils.java From vind with Apache License 2.0 | 4 votes |
public static CreateIndexRequest getCreateIndexRequest(String index) { final CreateIndexRequest request = new CreateIndexRequest(index); request.settings(ElasticMappingUtils.getDefaultSettings(), XContentType.JSON); request.mapping(ElasticMappingUtils.getDefaultMapping(), XContentType.JSON); return request; }