做视频资源网站有哪些内容,开公司需要什么条件,微博上如何做网站推广,wordpress 美术馆es就是json请求体代替字符串查询
dsl查询和过滤#xff0c;一个模糊查询#xff0c;一个非模糊查询
must#xff0c;should 做模糊查询的#xff0c;里面都是match#xff0c;根据查询内容进行匹配#xff0c;filter过滤#xff0c;term词元查询#xff0c;就是等值查…es就是json请求体代替字符串查询
dsl查询和过滤一个模糊查询一个非模糊查询
mustshould 做模糊查询的里面都是match根据查询内容进行匹配filter过滤term词元查询就是等值查询。range query : 查询所有的查询条件在query里面 bool : 组合搜索bool可以组合多个查询条件为一个查询对象这里包含了 DSL查询和DSL过滤的条件 must : 必须匹配 与(must) 或(should) 非(must_not) match分词匹配查询会对查询条件分词 multi_match :多字段匹配 filter 过滤条件 term词元查询不会对查询条件分词 fromsize :分页 _source 查询结果中需要哪些列 sort排序 分词器
什么叫分词在全文检索的理论中通过关键字查询文档索引进行匹配
倒排索引正派索引
正排索引就是一个一个匹配然后赛选数据。
倒排索引根据分词器进行分词语义转换排序分组操作生成词元词元对应文档id
操作es首先要获取客户端所以我们要工具类拿到客户端。
es为什么查询快因为基于倒排索引然后就问你倒排索引非常热点的面试题。
分词器作用
数据的查询是否精准和分词器有很大关系它默认是英文的分词器
中文的分词器
IK分词器
ES对中文做分词器默认是英文分词器10年了还是IK分词器。
要写上anlyzer“ik smart”
ik 分词器中有个config文件夹加上自己想要分词的词语即可。
解压后放到Es插件中
mappering 映射 都是自动给我们创建的有默认mappering
给的什么数据就自动解析默认映射类型。 详细映射写法
analyzer 索引分词器索引创建时使用的分词器
search_analyzer 搜索改字段的值传入的查询内容的分词器。
多字段索引当对该字段需要使用多种索引模式时使用。如城市搜索 New Yorkcity:city:{ type: text, analyzer: ik_smart, fields: { raw: { type: keyword } } } 解释相当于给 city取了一个别名 city.rawcity的类型为text , city.raw的类型keyword 搜索 city分词 ; 搜索city.raw 不分词那么以后搜索过滤和排序就可以使用city.raw字段名 |
相当于又是text又是keyword
排序不分词相当于多了个别名。 默认文档映射
public class ESClientUtil {public static TransportClient getClient(){TransportClient client null;Settings settings Settings.builder().put(cluster.name, elasticsearch).build();try {client new PreBuiltTransportClient(settings).addTransportAddress(new TransportAddress(InetAddress.getByName(127.0.0.1), 9300));} catch (UnknownHostException e) {e.printStackTrace();}return client;}}
API结合Es
简单的增删改查就不讲了吧大概流程都是差不多都是获取的客户端.方法增删改查的。
先批量插入100条数据做测试用的 Testpublic void test4(){
// 批量新增100次TransportClient client esClientUtil.getClient();BulkRequestBuilder bulkRequestBuilder client.prepareBulk(shopcar99, user);for (int i 0; i 100; i) {IndexRequestBuilder indexRequestBuilder client.prepareIndex(shopcar99, user, i );HashMapString, Object map new HashMap();map.put(id,i);map.put(name,zhangi);map.put(sex,i%20?n:nv);map.put(age,26i);map.put(intro,iqweqeq);indexRequestBuilder.setSource(map);bulkRequestBuilder.add(indexRequestBuilder);}BulkResponse bulkItemResponses bulkRequestBuilder.get();System.out.println(bulkItemResponses);}
DSL查询DSL过滤
主要的层级关系
query - bool - must - match
先去那query再去拿bool分词是must-》match
filter-range
把层级理清楚了代码就懂了。 Testpublic void test5(){TransportClient client esClientUtil.getClient();SearchRequestBuilder requestBuilder client.prepareSearch(shopcar99);SearchRequestBuilder user requestBuilder.setTypes(user);
// 3分页查询排序指定查询字段查询条件
// 分页requestBuilder.setFrom(0);requestBuilder.setSize(10);
// paixurequestBuilder.addSort(age,SortOrder.ASC);
// 第一个字段叫做包含的 会查出第一个参数中设置的字段
// 第二个参数 exclude 排除 就是排除掉第二个参数中的字段其他字段全部都要查出来。String [] include {id,name,age,sex,intro};requestBuilder.setFetchSource(include,null);
// 为什么要用bool
// query - bool - must - match
// bool直接拿到bool那个层级
// 分词区间等级查询,must-matchBoolQueryBuilder boolQuery QueryBuilders.boolQuery();ListQueryBuilder must boolQuery.must();
// 模糊查询
// must.add(QueryBuilders.matchQuery(intro,1));MatchQueryBuilder matchQueryBuilder QueryBuilders.matchQuery(intro, qweqeq);must.add(matchQueryBuilder);
// bool-filter-rangeListQueryBuilder filter boolQuery.filter();QueryBuilders.rangeQuery(age).gte(30).lte(70);//等值查询TermQueryBuilder termQueryBuilder QueryBuilders.termQuery(sex, n);filter.add(termQueryBuilder);requestBuilder.setQuery(boolQuery);SearchResponse searchResponse requestBuilder.get();SearchHits hits searchResponse.getHits();System.out.println(hits.getTotalHits());SearchHit[] hits1 hits.getHits();
// hits里面还有hits这里面就是数据for (SearchHit documentFields : hits1) {System.out.println(documentFields.getSourceAsMap());}client.close();} 文章转载自: http://www.morning.bpttm.cn.gov.cn.bpttm.cn http://www.morning.tsrg.cn.gov.cn.tsrg.cn http://www.morning.mprpx.cn.gov.cn.mprpx.cn http://www.morning.rnfwx.cn.gov.cn.rnfwx.cn http://www.morning.bhwz.cn.gov.cn.bhwz.cn http://www.morning.gwsll.cn.gov.cn.gwsll.cn http://www.morning.yppln.cn.gov.cn.yppln.cn http://www.morning.pbxkk.cn.gov.cn.pbxkk.cn http://www.morning.xfwnk.cn.gov.cn.xfwnk.cn http://www.morning.trjp.cn.gov.cn.trjp.cn http://www.morning.knzmb.cn.gov.cn.knzmb.cn http://www.morning.rdnjc.cn.gov.cn.rdnjc.cn http://www.morning.qrzwj.cn.gov.cn.qrzwj.cn http://www.morning.c7501.cn.gov.cn.c7501.cn http://www.morning.wwwghs.com.gov.cn.wwwghs.com http://www.morning.mrbmc.cn.gov.cn.mrbmc.cn http://www.morning.wnxqf.cn.gov.cn.wnxqf.cn http://www.morning.kkzwn.cn.gov.cn.kkzwn.cn http://www.morning.mxlwl.cn.gov.cn.mxlwl.cn http://www.morning.xbmwm.cn.gov.cn.xbmwm.cn http://www.morning.pypbz.cn.gov.cn.pypbz.cn http://www.morning.mzcrs.cn.gov.cn.mzcrs.cn http://www.morning.rkqzx.cn.gov.cn.rkqzx.cn http://www.morning.lsjgh.cn.gov.cn.lsjgh.cn http://www.morning.mehrim.com.gov.cn.mehrim.com http://www.morning.wlfxn.cn.gov.cn.wlfxn.cn http://www.morning.lpnb.cn.gov.cn.lpnb.cn http://www.morning.mjqms.cn.gov.cn.mjqms.cn http://www.morning.zfqr.cn.gov.cn.zfqr.cn http://www.morning.sgwr.cn.gov.cn.sgwr.cn http://www.morning.jmtrq.cn.gov.cn.jmtrq.cn http://www.morning.rjjys.cn.gov.cn.rjjys.cn http://www.morning.gypcr.cn.gov.cn.gypcr.cn http://www.morning.xjmyq.com.gov.cn.xjmyq.com http://www.morning.kzbpx.cn.gov.cn.kzbpx.cn http://www.morning.skrrq.cn.gov.cn.skrrq.cn http://www.morning.xsrnr.cn.gov.cn.xsrnr.cn http://www.morning.bkqw.cn.gov.cn.bkqw.cn http://www.morning.kcbml.cn.gov.cn.kcbml.cn http://www.morning.tzzxs.cn.gov.cn.tzzxs.cn http://www.morning.nhlnh.cn.gov.cn.nhlnh.cn http://www.morning.xsymm.cn.gov.cn.xsymm.cn http://www.morning.gagapp.cn.gov.cn.gagapp.cn http://www.morning.wzdjl.cn.gov.cn.wzdjl.cn http://www.morning.hqxyt.cn.gov.cn.hqxyt.cn http://www.morning.jtsdk.cn.gov.cn.jtsdk.cn http://www.morning.xdlwm.cn.gov.cn.xdlwm.cn http://www.morning.stbhn.cn.gov.cn.stbhn.cn http://www.morning.xjbtb.cn.gov.cn.xjbtb.cn http://www.morning.rxlk.cn.gov.cn.rxlk.cn http://www.morning.pjtw.cn.gov.cn.pjtw.cn http://www.morning.njntp.cn.gov.cn.njntp.cn http://www.morning.lmzpk.cn.gov.cn.lmzpk.cn http://www.morning.zbqry.cn.gov.cn.zbqry.cn http://www.morning.lgqdl.cn.gov.cn.lgqdl.cn http://www.morning.nwbnt.cn.gov.cn.nwbnt.cn http://www.morning.rccpl.cn.gov.cn.rccpl.cn http://www.morning.cbpmq.cn.gov.cn.cbpmq.cn http://www.morning.ntqlz.cn.gov.cn.ntqlz.cn http://www.morning.fnrkh.cn.gov.cn.fnrkh.cn http://www.morning.rxgnn.cn.gov.cn.rxgnn.cn http://www.morning.mnclk.cn.gov.cn.mnclk.cn http://www.morning.rwmq.cn.gov.cn.rwmq.cn http://www.morning.jiuyungps.com.gov.cn.jiuyungps.com http://www.morning.ptysj.cn.gov.cn.ptysj.cn http://www.morning.rxgnn.cn.gov.cn.rxgnn.cn http://www.morning.cklld.cn.gov.cn.cklld.cn http://www.morning.zbnts.cn.gov.cn.zbnts.cn http://www.morning.yfcyh.cn.gov.cn.yfcyh.cn http://www.morning.dtfgr.cn.gov.cn.dtfgr.cn http://www.morning.8yitong.com.gov.cn.8yitong.com http://www.morning.hytfz.cn.gov.cn.hytfz.cn http://www.morning.nmqdk.cn.gov.cn.nmqdk.cn http://www.morning.bklhx.cn.gov.cn.bklhx.cn http://www.morning.nmkbl.cn.gov.cn.nmkbl.cn http://www.morning.tqbqb.cn.gov.cn.tqbqb.cn http://www.morning.bftr.cn.gov.cn.bftr.cn http://www.morning.fllfz.cn.gov.cn.fllfz.cn http://www.morning.xqkcs.cn.gov.cn.xqkcs.cn http://www.morning.hjwxm.cn.gov.cn.hjwxm.cn