package com.test.web;

import com.fzd.elasticsearch.ESQueryBuilderConstructor;
import com.fzd.elasticsearch.ESQueryBuilders;
import com.fzd.elasticsearch.ElasticSearchService;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import java.net.InetAddress;

/**
 * Created by SRKJ on 2017/8/2.
 */
public class TestJDES {
    public static String host = "192.168.0.101";
    public static String cluster = "my-es";
    static TransportClient client = null;

    public static void main(String... args) {
        try {
            Settings settings = Settings.builder()
                    .put("cluster.name", cluster).build();
            client = new PreBuiltTransportClient(settings)
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), 9300));
            boolQuery();
        } catch (Exception e) {
            e.printStackTrace();
        }

        client.close();
    }

    private static void boolQuery() {
        ElasticSearchService elastic = new ElasticSearchService("my-es","192.168.0.101",9300);
        ESQueryBuilderConstructor constructor = new ESQueryBuilderConstructor();
//        constructor.setDesc("desc");
        constructor.setSize(10);
        ESQueryBuilders builders = new ESQueryBuilders();
        builders.term("telString","18482173967");
        builders.term("talkTel","18408249626");
        constructor.must(builders);
        Terms stateAgg = elastic.statSearch("mobileinfo","callrecords",constructor,"");
        System.out.println(stateAgg);
    }

}
