• 大小: 0.1M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-04
  • 语言: 其他
  • 标签: 其他  

资源简介

yan-study-dev.zip

资源截图

代码片段和文件信息

package cn.yan.study.es;

/**
 * Created 没有用
 * User  wankunYan
 * Date  2018/6/26
 * Time  14:21
 */

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import cn.yan.study.es.client.EsClient;
import cn.yan.study.es.index.Index;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.common.settings.Settings;

public class Elasticsearch {
    private Client client;
    private IndicesAdminClient adminClient;
    /**
     * 集群配置初始化方法
     * @throws Exception
     */
    private void init() throws Exception{
        client = EsClient.getTransportClient();
    }
    /**
     * 构造方法
     */
    public Elasticsearch() {
        try {
            init();
        } catch (Exception e) {
            System.out.println(“init() exception!“);
            e.printStackTrace();
        }
        adminClient = client.admin().indices();
    }
    /**
     * 判断集群中{index}是否存在
     * @param index
     * @return 存在(true)、不存在(false)
     */
    public boolean indexExists(String index){
        IndicesExistsRequest request = new IndicesExistsRequest(index);
        IndicesExistsResponse response = adminClient.exists(request).actionGet();
        if (response.isExists()) {
            return true;
        }
        return false;
    }
    /**
     * 读取es配置信息
     * @return
     */
    private Properties readElasticsearchConfig() {
        Properties properties = new Properties();
        try {
            InputStream is = this.getClass().getClassLoader().getResourceAsStream(“elasticsearch.properties“);
            properties.load(new InputStreamReader(is“UTF-8“));
        } catch (IOException e) {
            System.out.println(“readEsConfig exception!“);
            e.printStackTrace();
        }
        return properties;
    }
    /**
     * 获取要创建的index列表
     * @return List
     */
    public List getIndexList(){
        List indexList = new ArrayList<>();
        Index index1 = new Index(“index_one“ “type_one“ 4 5 “{\“initType\“:{\“properties\“:{\“date\“:{\“format\“:\“yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis\“\“type\“:\“date\“}\“name\“:{\“type\“:\“String\“}}}}“);
        indexList.add(index1);
        return indexList;
    }
    /**
     * 创建Index
     */
    public void CreateIndex(){
        int i = 0;
        List list = getIndexList();
        IndicesAdminClient adminClient = client.admin().indices();
        for(Index index : list){
            if (indexExists(index.getIndex())) {
                continue;
            }
            adminClient.prepareCreate(index.getIndex())
                    .setSettings(Settings.builder().put(“index.number_of_shards“ index.getNumber_of_shar

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-02-19 02:37  yan-study-dev\
     文件         106  2019-02-19 02:37  yan-study-dev\.gitignore
     文件          49  2019-02-19 02:37  yan-study-dev\README.md
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\
     文件        2848  2019-02-19 02:37  yan-study-dev\elasticsearch-study\pom.xml
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\
     文件        3506  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\Elasticsearch.java
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\client\
     文件        1259  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\client\EsClient.java
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\index\
     文件        1639  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\index\Index.java
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\test\
     文件        3667  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\test\EsParentChildTest.java
     文件        1501  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\test\School.java
     文件        1500  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\test\Student.java
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\utils\
     文件        4051  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\utils\EsAdminClientUtils.java
     文件        9055  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\java\cn\yan\study\es\utils\EsClientUtils.java
     目录           0  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\resources\
     文件          65  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\resources\elasticsearch.properties
     文件         675  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\resources\index.json
     文件         399  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\resources\log4j2.xml
     文件         679  2019-02-19 02:37  yan-study-dev\elasticsearch-study\src\main\resources\me.txt
     文件         757  2019-02-19 02:37  yan-study-dev\pom.xml
     目录           0  2019-02-19 02:37  yan-study-dev\queue-study\
............此处省略170个文件信息

评论

共有 条评论