ElasticSearch搜索

最后更新:2024-09-26 05:30:15 | 状态:未完成 | 相关数据库: ElasticSearch-Elasticsearch
//通用查询条件
ElasticSearchConfigStore configs = new ElasticSearchConfigStore();
configs.order("effect", "asc").order("pub_ymd", "desc");
configs.page(2, 3);//第2页 每页3行
configs.addHighlight("title", "content");
configs.match("content,title.keyword", "实时");  //multi_match
configs.or(Compare.MATCH, "content", "扩展");
configs.and(Compare.MATCH, "content", "集群");
//configs.and(Compare.IN,"type_code","4","5","6");
configs.collapse("yyyy");
//configs.order("yyyy");
configs.setJoin(Condition.JOIN.FILTER); //and(must)和or(should)可以自动识别 其他的需要设置
DataSet set = ServiceProxy.querys(table_name, configs);
System.out.println(set.toString());

//复杂的查询可以构造JSON
String json = "{\"from\":13,\"size\":10,\"collapse\":{\"field\":\"yyyy\"},\"highlight\":{\"fields\":{\"title\":{},\"content\":{}}},\"query\":{\"bool\":{\"filter\":[{\"bool\":{\"should\":[{\"multi_match\":{\"query\":\"实时\",\"fields\":[\"content\",\"title.keyword\"]}},{\"match\":{\"content\":\"扩展\"}}]}},{\"match\":{\"content\":\"集群\"}}]}},\"sort\":[{\"effect\":{\"order\":\"asc\"}},{\"pub_ymd\":{\"order\":\"desc\"}}]}";
configs.setRequestBody(json);
ServiceProxy.querys(configs);
//默认查10行
DataSet set = ServiceProxy.querys(table_name);
System.out.println(set.size()+"/"+set.total());

//通用查询条件
ElasticSearchConfigStore configs = new ElasticSearchConfigStore();

configs.match("content", "集群");
set = ServiceProxy.querys(table_name, configs);
System.out.println(set.toString());

//复杂的查询直接设置request body 参数格式参考  https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html#search-search-api-query-params
configs = new ElasticSearchConfigStore();
DataRow row = new DataRow(KeyAdapter.KEY_CASE.SRC);
row.put("query").put("match_all", new DataRow());
row.put("from", 2);
row.put("size", 3);
configs.setRequestBody(row.json());
set = ServiceProxy.querys(table_name, configs);
System.out.println(set.toString());

首页 最近更新 搜索 提交 回复