Java Code Examples for org.elasticsearch.action.admin.indices.create.CreateIndexRequest#alias()
The following examples show how to use
org.elasticsearch.action.admin.indices.create.CreateIndexRequest#alias() .
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: RandomCreateIndexGenerator.java From crate with Apache License 2.0 | 5 votes |
/** * Sets random aliases to the provided {@link CreateIndexRequest} */ public static void randomAliases(CreateIndexRequest request) { int aliasesNo = randomIntBetween(0, 2); for (int i = 0; i < aliasesNo; i++) { request.alias(randomAlias()); } }
Example 2
Source File: EsAggregationSearchTest.java From java-study with Apache License 2.0 | 4 votes |
/** * 创建索引 * * @throws IOException */ private static void createIndex() throws IOException { // 类型 String type = "_doc"; String index = "student"; // setting 的值 Map<String, Object> setmapping = new HashMap<>(); // 分区数、副本数、缓存刷新时间 setmapping.put("number_of_shards", 10); setmapping.put("number_of_replicas", 1); setmapping.put("refresh_interval", "5s"); Map<String, Object> keyword = new HashMap<>(); //设置类型 keyword.put("type", "keyword"); Map<String, Object> lon = new HashMap<>(); //设置类型 lon.put("type", "long"); Map<String, Object> date = new HashMap<>(); //设置类型 date.put("type", "date"); date.put("format", "yyyy-MM-dd"); Map<String, Object> date2 = new HashMap<>(); //设置类型 date2.put("type", "date"); date2.put("format", "yyyy-MM-dd HH:mm:ss.SSS"); Map<String, Object> jsonMap2 = new HashMap<>(); Map<String, Object> properties = new HashMap<>(); //设置字段message信息 properties.put("uid", lon); properties.put("grade", lon); properties.put("class", lon); properties.put("age", lon); properties.put("name", keyword); properties.put("createtm", date); properties.put("updatetm", date2); Map<String, Object> mapping = new HashMap<>(); mapping.put("properties", properties); jsonMap2.put(type, mapping); GetIndexRequest getRequest = new GetIndexRequest(); getRequest.indices(index); getRequest.types(type); getRequest.local(false); getRequest.humanReadable(true); boolean exists2 = client.indices().exists(getRequest, RequestOptions.DEFAULT); //如果存在就不创建了 if(exists2) { System.out.println(index+"索引库已经存在!"); return; } // 开始创建库 CreateIndexRequest request = new CreateIndexRequest(index); try { // 加载数据类型 request.settings(setmapping); //设置mapping参数 request.mapping(type, jsonMap2); //设置别名 request.alias(new Alias("pancm_alias")); CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); boolean falg = createIndexResponse.isAcknowledged(); if(falg){ System.out.println("创建索引库:"+index+"成功!" ); } } catch (IOException e) { e.printStackTrace(); } }
Example 3
Source File: EsUtil.java From java-study with Apache License 2.0 | 4 votes |
/** * @return boolean * @Author pancm * @Description //创建索引库(指定Mpping类型) * @Date 2019/3/21 * @Param [esBasicModelConfig] **/ public static boolean creatIndex(EsBasicModelConfig esBasicModelConfig) throws IOException { boolean falg = true; Objects.requireNonNull(esBasicModelConfig, "esBasicModelConfig is not null"); String type = Objects.requireNonNull(esBasicModelConfig.getType(), "type is not null"); String index = Objects.requireNonNull(esBasicModelConfig.getIndex(), "index is not null"); if (exitsIndex(index)) { logger.warn("索引库{}已经存在!无需在进行创建!", index); return true; } String mapping = esBasicModelConfig.getMappings(); Map<String, Object> setting = esBasicModelConfig.getSettings(); String alias = esBasicModelConfig.getAlias(); // 开始创建库 CreateIndexRequest request = new CreateIndexRequest(index); try { if (Objects.nonNull(mapping)) { // 加载数据类型 request.mapping(type, mapping); } if (Objects.nonNull(setting)) { // 分片数 request.settings(setting); } if (Objects.nonNull(alias)) { // 别名 request.alias(new Alias(alias)); } CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); falg = createIndexResponse.isAcknowledged(); } catch (IOException e) { throw e; } finally { if (isAutoClose) { close(); } } return falg; }
Example 4
Source File: EsHighLevelRestTest1.java From java-study with Apache License 2.0 | 4 votes |
/** * 创建索引 * * @throws IOException */ private static void createIndex() throws IOException { // 类型 String type = "_doc"; String index = "test1"; // setting 的值 Map<String, Object> setmapping = new HashMap<>(); // 分区数、副本数、缓存刷新时间 setmapping.put("number_of_shards", 10); setmapping.put("number_of_replicas", 1); setmapping.put("refresh_interval", "5s"); Map<String, Object> keyword = new HashMap<>(); //设置类型 keyword.put("type", "keyword"); Map<String, Object> lon = new HashMap<>(); //设置类型 lon.put("type", "long"); Map<String, Object> date = new HashMap<>(); //设置类型 date.put("type", "date"); date.put("format", "yyyy-MM-dd HH:mm:ss"); Map<String, Object> jsonMap2 = new HashMap<>(); Map<String, Object> properties = new HashMap<>(); //设置字段message信息 properties.put("uid", lon); properties.put("phone", lon); properties.put("msgcode", lon); properties.put("message", keyword); properties.put("sendtime", date); Map<String, Object> mapping = new HashMap<>(); mapping.put("properties", properties); jsonMap2.put(type, mapping); GetIndexRequest getRequest = new GetIndexRequest(); getRequest.indices(index); getRequest.types(type); getRequest.local(false); getRequest.humanReadable(true); boolean exists2 = client.indices().exists(getRequest, RequestOptions.DEFAULT); //如果存在就不创建了 if(exists2) { System.out.println(index+"索引库已经存在!"); return; } // 开始创建库 CreateIndexRequest request = new CreateIndexRequest(index); try { // 加载数据类型 request.settings(setmapping); //设置mapping参数 request.mapping(type, jsonMap2); //设置别名 request.alias(new Alias("pancm_alias")); CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); boolean falg = createIndexResponse.isAcknowledged(); if(falg){ System.out.println("创建索引库:"+index+"成功!" ); } } catch (IOException e) { e.printStackTrace(); } }