All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.plumelog.server.es.ElasticLowerClient Maven / Gradle / Ivy

package com.plumelog.server.es;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.elasticsearch.client.*;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class ElasticLowerClient {
    private  org.slf4j.Logger logger= LoggerFactory.getLogger(ElasticLowerClient.class);
    private static ElasticLowerClient instance;
    private RestClient client;

    public static ElasticLowerClient getInstance(String hosts,String userName,String passWord) {
        if (instance == null) {
            synchronized (ElasticLowerClient.class) {
                if (instance == null) {
                    instance = new ElasticLowerClient(hosts,userName,passWord);
                }
            }
        }
        return instance;
    }
    public ElasticLowerClient(String hosts,String userName,String passWord) {

        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, passWord));  //es账号密码
        String[] hostsAndPorts=hosts.split(",");
        HttpHost[] httpHosts = new HttpHost[hostsAndPorts.length];
        for(int i=0;i getExistIndices(String [] indices){
        List existIndexList = new ArrayList();
        for (String index: indices){
            try {
                Request request = new Request(
                        "HEAD",
                        "/"+index+"");
                Response res=client.performRequest(request);
                if(res.getStatusLine().getStatusCode()==200){
                    existIndexList.add(index);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return existIndexList;
    }
    public void insertList(List list,String baseIndex,String type) throws IOException {
        StringBuffer sendStr=new StringBuffer();
        for(int a=0;a




© 2015 - 2025 Weber Informatics LLC | Privacy Policy