elasticsearch java api 入门
本文章记录elasticsearch学习笔记:
- elasticsearch简介
- elasticsear java api使用
elasticsearch 简介
回头补充
elasticsearch java api 使用
引入的包
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import com.alibaba.dubbo.common.utils.CollectionUtils;
import com.zichan360.case_model.constant.CaseConstant;
import com.zichan360.case_model.model.CaseEsSearchResult;
import com.zichan360.case_model.util.DateUtil;
import com.zichan360.case_model.util.ElasticSearchUtil;
import org.apache.commons.lang3.math.NumberUtils;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.junit.Test;
集群链接
// 设置settings
Settings settings = Settings.builder().put("cluster.name", "es-java").build();
// 创建client
TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.100.10"), 9300));
查看索引信息
//索引管理客户端
IndicesAdminClient indicesAdminClient = client.admin().indices();
//查看所有索引
String[] indics=indicesAdminClient.prepareGetIndex().get().getIndices();
多字段进行比较
boolQueryBuilder.must(QueryBuilders.scriptQuery(new Script("doc['time1'].value <= doc['time2'].value")));