ElasticSearchyanjiu2021-04-27 11:15·suifengElasticSearchjieshaoESxiangguanjishuwendang,henjiuzhiqiankande,yimenjishushijianchangbuquyanjiujiuhuirongyiwangliao,yingyouxiexiaohuobandeyaoqiuxiwangwozuoyiqiESjishuzhuanlan,wojiubayiqiankanguodexiangguanwendanghebijizhenglizhengli,geidajiafenxiangxia。ElasticSearchjieshaojieshaoguanfangwangzhi:https://www.elastic.co/cn/products/elasticsearchGithub:https://github.com/elastic/elasticsearchzongjie:1、elasticsearchshiyigejiyuLucenedegaokuozhandefenbushisousuofuwuqi,zhichikaixiangjiyong。2、elasticsearchyincangliaoLucenedefuzaxing,duiwaitigongRestful jiekoulaicaozuosuoyin、sousuo。tuchuyoudian:1.kuozhanxinghao,kebushushangbaitaifuwuqijiqun,chuliPBjishuju。2.jinshishidiqusuoyinshuju、sousuoshuju。eshesolrxuanzenage?1.ruguonigongsixianzaiyongdesolrkeyimanzuxuqiujiubuyaohuanliao。2.ruguonigongsizhunbeijinxingquanwenjiansuoxiangmudekaifa,jianyiyouxiankaolvelasticsearch,yinweixiangGithubzheyangdaguimodesousuoduzaiyongta。yuanliyuyingyongsuoyinjiegouxiatushiElasticSearchdesuoyinjiegou,xiabianheisebufenshiwulijiegou,shangbianhuangsebufenshiluojijiegou,luojijiegouyeshiweiliaogenghaodequmiaoshuElasticSearchdegongzuoyuanlijiqushiyongwulijiegouzhongdesuoyinwenjian。luojijiegoubufenshiyigedaopaisuoyinbiao:1、jiangyaosousuodewendangneirongfenci,suoyoubuzhongfudecizuchengfenciliebiao。2、jiangsousuodewendangzuizhongyiDocumentfangshicunchuqilai。3、meigecihedocmentduyouguanlian。ruxia:xianzai,ruguowomenxiangsousuo quick brown ,womenzhixuyaochazhaobaohanmeigecitiaodewendang:lianggewendangdupipei,danshidiyigewendangbidiergepipeidugenggao。ruguowomenshiyongjinjisuanpipeicitiaoshuliangdejiandan xiangsixingsuanfa,name,womenkeyishuo,duiyuwomenchaxundexiangguanxinglaijiang,diyigewendangbidiergewendanggengjia。RESTfulyingyongfangfaruheshiyonges?Elasticsearchtigong RESTful Apijiekoujinxingsuoyin、sousuo,bingqiezhichiduozhongkehuduan。xiatushieszaixiangmuzhongdeyingyongfangshi:1)yonghuzaiqianduansousuoguanjianzi2)xiangmuqianduantongguohttpfangshiqingqiuxiangmufuwuduan3)xiangmufuwuduantongguoHttp RESTfulfangshiqingqiuESjiqunjinxingsousuo4)ESjiquncongsuoyinkujiansuoshuju。ElasticaSearchanzhuanganzhuanganzhuangpeizhi:1、xinbanbenyaoqiuzhishaojdk1.8yishang。2、zhichitar、zip、rpmdengduozhonganzhuangfangshi。zaiwindowsxiakaifajianyishiyongZIPanzhuangfangshi。3、zhichidockerfangshianzhuangxiangxicanjian:https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.htmlxiazaiES: Elasticsearch 6.2.1https://www.elastic.co/downloads/past-releasesjieya elasticsearch-6.2.1.zipbin:jiaobenmulu,baokuo:qidong、tingzhidengkezhixingjiaobenconfig:peizhiwenjianmuludata:suoyinmulu,cunfangsuoyinwenjiandedifanglogs:rizhimulumodules:mokuaimulu,baokuoliaoesdegongnengmokuaiplugins :chajianmulu,eszhichichajianjizhipeizhiwenjiansangepeizhiwenjianESdepeizhiwenjiandedizhigenjuanzhuangxingshidebutongerbutong:shiyongzip、taranzhuang,peizhiwenjiandedizhizaianzhuangmuludeconfigxia。shiyongRPManzhuang,peizhiwenjianzai/etc/elasticsearchxia。shiyongMSIanzhuang,peizhiwenjiandedizhizaianzhuangmuludeconfigxia,bingqiehuizidongjiangconfigmuludizhixieruhuanjingbianliangES_PATH_CONF。benjiaochengshiyongdezipbaoanzhuang,peizhiwenjianzaiESanzhuangmuludeconfigxia。peizhiwenjianruxia:elasticsearch.yml : yongyupeizhiElasticsearchyunxingcanshu jvm.options : yongyupeizhiElasticsearch JVMshezhi log4j2.properties: yongyupeizhiElasticsearchrizhielasticsearch.ymlpeizhigeshishiYAML,keyicaiyongruxialiangzhongfangshi:fangshi1:cengcifangshipath: data: /var/lib/elasticsearch logs: /var/log/elasticsearchfangshi2:shuxingfangshipath.data: /var/lib/elasticsearch path.logs: /var/log/elasticsearchbenxiangmucaiyongfangshi2,liziruxia:cluster.name: xuechengnode.name: xc_node_1network.host: 0.0.0.0http.port: 9200transport.tcp.port: 9300node.master: truenode.data: true#discovery.zen.ping.unicast.hosts: ["0.0.0.0:9300", "0.0.0.0:9301", "0.0.0.0:9302"]discovery.zen.minimum_master_nodes: 1bootstrap.memory_lock: falsenode.max_local_storage_nodes: 1path.data: D:\ElasticSearch\elasticsearch-6.2.1\datapath.logs: D:\ElasticSearch\elasticsearch-6.2.1\logshttp.cors.enabled: truehttp.cors.allow-origin: /.*/zhuyipath.datahepath.logslujingpeizhizhengque。changyongdepeizhixiangruxia:cluster.name:peizhielasticsearchdejiqunmingcheng,morenshielasticsearch。jianyixiugaichengyigeyouyiyidemingcheng。node.name:jiedianming,tongchangyitaiwulifuwuqijiushiyigejiedian,eshuimorensuijizhidingyigemingzi,jianyizhidingyigeyouyiyidemingcheng,fangbianguanliyigehuoduogejiedianzuchengyigeclusterjiqun,jiqunshiyigeluojidegainian,jiedianshiwuligainian,houbianzhangjiehuixiangxijieshao。path.conf: shezhipeizhiwenjiandecunchulujing,tarhuozipbaoanzhuangmorenzaiesgenmuluxiadeconfigwenjianjia,rpmanzhuangmorenzai/etc/ elasticsearch path.data: shezhisuoyinshujudecunchulujing,morenshiesgenmuluxiadedatawenjianjia,keyishezhiduogecunchulujing,yongdouhaogekai。 path.logs: shezhirizhiwenjiandecunchulujing,morenshiesgenmuluxiadelogswenjianjia path.plugins: shezhichajiandecunfanglujing,morenshiesgenmuluxiadepluginswenjianjiabootstrap.memory_lock: true shezhiweitruekeyisuozhuESshiyongdeneicun,bimianneicunyuswapfenqujiaohuanshuju。 network.host: shezhibangdingzhujideipdizhi,shezhiwei0.0.0.0biaoshibangdingrenheip,yunxuwaiwangfangwen,shengchanhuanjingjianyishezhiweijutideip。 http.port: 9200 shezhiduiwaifuwudehttpduankou,morenwei9200。transport.tcp.port: 9300 jiqunjiedianzhijiantongxinduankounode.master: zhidinggaijiedianshifouyouzigebeixuanjuchengweimasterjiedian,morenshitrue,ruguoyuanlaidemasterzuojihuizhongxinxuanjuxindemaster。 node.data: zhidinggaijiedianshifoucunchusuoyinshuju,morenweitrue。discovery.zen.ping.unicast.hosts: ["host1:port", "host2:port", "..."] shezhijiqunzhongmasterjiediandechushiliebiao。discovery.zen.ping.timeout: 3s shezhiESzidongfaxianjiedianlianjiechaoshideshijian,morenwei3miao,ruguowangluoyanchigaokeshezhidaxie。 discovery.zen.minimum_master_nodes:zhujiedianshuliangdezuishaozhi ,cizhidegongshiwei:(master_eligible_nodes / 2) + 1 ,biru:you3gefuheyaoqiudezhujiedian,namezheliyaoshezhiwei2。node.max_local_storage_nodes:danjiyunxudezuidacunchujiedianshu,tongchangdanjiqidongyigejiedianjianyishezhiwei1,kaifahuanjingruguodanjiqidongduogejiediankeshezhidayu1.jvm.optionsshezhizuixiaojizuidadeJVMduineicundaxiao:zaijvm.optionszhongshezhi -Xmshe-Xmx:1) lianggezhishezhiweixiangdeng2) jiangXmx shezhiweibuchaoguowulineicundeyiban。log4j2.propertiesrizhiwenjianshezhi,ESshiyonglog4j,zhuyirizhijibiedepeizhi。xitongpeizhizailinuxshanggenjuxitongziyuanqingkuang,kejiangmeigejinchengzuiduoyunxudakaidewenjianshushezhidaxie。su limit -n chaxundangqianwenjianshushiyongminglingshezhilimit:xianqiehuandaoroot,shezhiwanchengzaiqiehuielasticsearchyonghu。sudo su ulimit -n 65536 su elasticsearch yeketongguoxiabiandefangshixiugaiwenjianjinxingchijiushezhi/etc/security/limits.confjiangxiabiandexingjiaruciwenjian:elasticsearch - nofile 65536qidongESjinrubinmulu,zaicmdxiayunxing:elasticsearch.batzuolanqishuru:http://localhost:9200xianshijieguoruxia(peizhibutongneirongzebutong)shuomingESqidongchenggong:{ "name" : "xc_node_1", "cluster_name" : "xuecheng", "cluster_uuid" : "J18wPybJREyx1kjOoH8T-g", "version" : { "number" : "6.2.1", "build_hash" : "7299dc3", "build_date" : "2018-02-07T19:34:26.990113Z", "build_snapshot" : false, "lucene_version" : "7.2.1", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search"}headchajiananzhuangheadchajianshiESdeyigekeshihuaguanlichajian,yonglaijianshiESdezhuangtai,bingtongguoheadkehuduanheESfuwujinxingjiaohu,biruchuangjianyingshe、chuangjiansuoyindeng,headdexiangmudizhizaihttps://github.com/mobz/elasticsearch-head 。congES6.0kaishi,headchajianzhichishidenode.jsyunxing。1、anzhuangnode.js2、xiazaiheadbingyunxinggit clone git://github.com/mobz/elasticsearch-head.git cd elasticsearch-head npm install npm run start open HTTP://bendizhuji:9100 /3、yunxingdakaizuolanqidiaoshigongjufaxianbaocuo:Origin null is not allowed by Access-Control-Allow-Origin.yuanyinshi:headchajianzuoweikehuduanyaolianjieESfuwu(localhost:9200),cishicunzaikuayuwenti,elasticsearchmorenbuyunxukuayufangwen。jiejuefangan:shezhielasticsearchyunxukuayufangwen。zaiconfig/elasticsearch.yml houmianzengjiayixiacanshu:#kaiqicorskuayufangwenzhichi,morenweifalse http.cors.enabled: true #kuayufangwenyunxudeyumingdizhi,(yunxusuoyouyuming)yishangshiyongzhengze http.cors.allow-origin: /.*/zhuyi:jiangconfig/elasticsearch.ymllingcunweiutf-8bianmageshi。chenggonglianjieESESkuaisurumenESzuoweiyigesuoyinjisousuofuwu,duiwaitigongfengfudeRESTjiekou,kuaisurumenbufendeshilishiyongheadchajianlaiceshi,mudeshiduiESdeshiyongfangfajiliuchengyougechubuderenshi。chuangjiansuoyinkuESdesuoyinkushiyigeluojigainian,tabaokuoliaofenciliebiaojiwendangliebiao,tongyigesuoyinkuzhongcunchuliaoxiangtongleixingdewendang。tajiuxiangdangyuMySQLzhongdebiao,huoxiangdangyuMongodbzhongdejihe。guanyusuoyinzhegeci:suoyin(mingci):ESshijiyuLucenegoujiandeyigesousuofuwu,tayaocongsuoyinkusousuofuhetiaojiansuoyinshuju。suoyin(dongci):suoyinkugangchuangjianqilaishikongde,jiangshujutianjiadaosuoyinkudeguochengchengweisuoyin。xiabianjieshaoliangzhongchuangjiansuoyinkudefangfa,tamendegongzuoyuanlishixiangtongde,dushikehuduanxiangESfuwufasongmingling。1)shiyongpostmanhuocurlzheyangdegongjuchuangjian:put http://localhost:9200/suoyinkumingcheng{ "settings":{ "index":{ "number_of_shards":1, "number_of_replicas":0 } }}number_of_shards:shezhifenpiandeshuliang,zaijiqunzhongtongchangshezhiduogefenpian,biaoshiyigesuoyinkujiangchaifenchengduopianfenbiecunchubutongdejiedian,tigaoliaoESdechulinenglihegaokeyongxing,rumenchengxushiyongdanjihuanjing,zhelishezhiwei1。number_of_replicas:shezhifubendeshuliang,shezhifubenshiweiliaotigaoESdegaokekaoxing,danjihuanjingshezhiwei0.ruxiashichuangjiandelizi,chuangjianxc_coursesuoyinku,gong1gefenpian,0gefuben:2)shiyongheadchajianchuangjianxiaoguoruxia:chuangjianyingshegainianshuomingzaisuoyinzhongmeigewendangdubaokuoliaoyigehuoduogefield,chuangjianyingshejiushixiangsuoyinkuzhongchuangjianfielddeguocheng,xiabianshidocumenthefieldyuguanxishujukudegainiandeleibi:wendang(Document)----------------Rowjiluziduan(Field)-------------------Columns liezhuyi:6.0zhiqiandebanbenyoutype(leixing)gainian,typexiangdangyuguanxishujukudebiao,ESguanfangjiangzaiES9.0banbenzhongchedishanchutype。shangbianjiangdechuangjiansuoyinkuxiangdangyuguanxishujukuzhongdeshujukuhuanshibiao?1、ruguoxiangdangyushujukujiubiaoshiyigesuoyinkukeyichuangjianhenduobutongleixingdewendang,zhezaiESzhongyeshiyunxude。2、ruguoxiangdangyubiaojiubiaoshiyigesuoyinkuzhinengcunchuxiangtongleixingdewendang,ESguanfangjianyi zaiyigesuoyinkuzhongzhicunchuxiangtongleixingdewendang。chuangjianyingshewomenyaobakechengxinxicunchudaoESzhong,zheliwomenchuangjiankechengxinxideyingshe,xianlaiyigejiandandeyingshe,ruxia:fasong:post http://localhost:9200/suoyinkumingcheng/leixingmingcheng/_mappingchuangjianleixingweixc_coursedeyingshe,gongbaokuosangeziduan:name、description、studymondelyouyuES6.0banbenhuanmeiyoujiangtypechedishanchu,suoyizanshibatypeqiyigemeiyouteshuyiyidemingzi。post qingqiu:http://localhost:9200/xc_course/doc/_mappingbiaoshi:zaixc_coursesuoyinkuxiadedocleixingxiachuangjianyingshe。docshileixingming,keyizidingyi,zaiES6.0zhongyaoruohualeixingdegainian,geitaqiyigemeiyoujutiyewuyiyidemingcheng。 { "properties": { "name": { "type": "text" }, "description": { "type": "text" }, "studymodel": { "type": "keyword" } }}yingshechuangjianchenggong,chakanheadjiemian:chuangjianwendangESzhongdewendangxiangdangyuMySQLshujukubiaozhongdejilu。fasong:put huoPost http://localhost:9200/xc_course/doc/idzhi(ruguobuzhidingidzhiEShuizidongshengchengID)http://localhost:9200/xc_course/doc/4028e58161bcf7f40161bcf8b77c0000{ "name":"Bootstrapkaifakuangjia", "description":"BootstrapshiyouTwittertuichudeyigeqiantaiyemiankaifakuangjia,zaixingyezhizhongshiyongjiaoweiguangfan。cikaifakuangjiabaohanliaodaliangdeCSS、JSchengxudaima,keyibangzhukaifazhe(youqishibushanchangyemiankaifadechengxurenyuan)qingsongdeshixianyigebushouzuolanqixianzhidejingmeijiemianxiaoguo。", "studymodel":"201001"}shiyongpostmanceshi:tongguoheadchaxunshuju:sousuowendang1、genjukechengidchaxunwendangfasong:get http://localhost:9200/xc_course/doc/4028e58161bcf7f40161bcf8b77c0000shiyongpostmanceshi:2、chaxunsuoyoujilufasong get http://localhost:9200/xc_course/doc/_search3、chaxunmingchengzhongbaokuospring guanjianzidedejilufasong:get http://localhost:9200/xc_course/doc/_search?q=name:bootstrap4、chaxunxueximoshiwei201001dejilufasong get http://localhost:9200/xc_course/doc/_search?q=studymodel:201001chaxunjieguofenxifenxishangbianchaxunjieguo:{ "took": 1, "timed_out": false, "_shards": { "total": 1, "successful": 1, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 0.2876821, "hits": [ { "_index": "xc_course", "_type": "doc", "_id": "4028e58161bcf7f40161bcf8b77c0000", "_score": 0.2876821, "_source": { "name": "Bootstrapkaifakuangjia", "description": "BootstrapshiyouTwittertuichudeyigeqiantaiyemiankaifakuangjia,zaixingyezhizhongshiyongjiaoweiguangfan。cikaifakuangjiabaohanliaodaliangdeCSS、JSchengxudaima,keyibangzhukaifazhe(youqishibushanchangyemiankaifadechengxurenyuan)qingsongdeshixianyigebushouzuolanqixianzhidejingmeijiemianxiaoguo。", "studymodel": "201001" } } ] }}took:bencicaozuohuafeideshijian,danweiweihaomiao。timed_out:qingqiushifouchaoshi_shards:shuomingbencicaozuogongsousuoliaonaxiefenpianhits:sousuomingzhongdejiluhits.total : fuhetiaojiandewendangzongshu hits.hits :pipeidujiaogaodeqianNgewendanghits.max_score:wendangpipeidefen,zheliweizuigaofen_score:meigewendangduyouyigepipeidudefen,anzhaojiangxupailie。_source:xianshiliaowendangdeyuanshineirong。IKfenciqiceshifenciqizaitianjiawendangshihuijinxingfenci,suoyinzhongcunfangdejiushiyigeyigedeci(term),dangniqusousuoshijiushinaguanjianziqupipeici,zuizhongzhaodaociguanliandewendang。ceshidangqiansuoyinkushiyongdefenciqi:post fasong:localhost:9200/_analyze{"text":"ceshifenciqi,houbianshiceshineirong:spring cloudshizhan"}jieguoruxia:huifaxianfencidexiaoguojiang “ceshi” zhegecichaifenchenglianggedanzi“ce”he“shi”,zheshiyinweidangqiansuoyinkushiyongdefenciqiduizhongwenjiushidanzifenci。anzhuangIKfenciqishiyongIKfenciqikeyishixianduizhongwenfencidexiaoguo。xiazaiIKfenciqi:(Githubdizhi:https://github.com/medcl/elasticsearch-analysis-ik)xiazaizip:jieya,bingjiangjieyadewenjiankaobeidaoESanzhuangmuludepluginsxiadeikmuluxiaceshifencixiaoguo:fasong:post localhost:9200/_analyze{"text":"ceshifenciqi,houbianshiceshineirong:spring cloudshizhan","analyzer":"ik_max_word" }liangzhongfencimoshiikfenciqiyouliangzhongfencimoshi:ik_max_wordheik_smartmoshi。1、ik_max_wordhuijiangwenbenzuozuixilidudechaifen,biruhuijiang“zhonghuarenmingongheguorenmindahuitang”chaifenwei“zhonghuarenmingongheguo、zhonghuarenmin、zhonghua、huaren、renmingongheguo、renmin、gongheguo、dahuitang、dahui、huitangdengciyu。2、ik_smarthuizuozuiculidudechaifen,biruhuijiang“zhonghuarenmingongheguorenmindahuitang”chaifenweizhonghuarenmingongheguo、renmindahuitang。ceshiliangzhongfencimoshi:fasong:post localhost:9200/_analyze{"text":"zhonghuarenmingongheguorenmindahuitang","analyzer":"ik_smart" }zidingyicikuruguoyaorangfenciqizhichiyixiezhuanyouciyu,keyizidingyiciku。iKfenciqizidaiyigemain.dicdewenjian,ciwenjianweicikuwenjian。zaishangbiandemuluzhongxinjianyigemy.dicwenjian(zhuyiwenjiangeshiweiutf-8(buyaoxuanzeutf-8 BOM))keyizaiqizhongzidingyicihui:birudingyi:peizhiwenjianzhongpeizhimy.dic,zhongqiES,ceshifencixiaoguo:fasong:post localhost:9200/_analyze{"text":"ceshifenciqi,houbianshiceshineirong:spring cloudshizhan","analyzer":"ik_max_word" }yingsheshangbianzhangjieanzhuangliaoikfenciqi,ruguozaisuoyinhesousuoshiqushiyongikfenciqine?ruhezhidingqitaleixingdefield,biruriqileixing、shuzhileixingdeng。benzhangjiexuexigezhongyingsheleixingjiyingsheweihufangfa。yingsheweihufangfa1、chaxunsuoyousuoyindeyingshe:GET: http://localhost:9200/_mapping2、chuangjianyingshepost qingqiu:http://localhost:9200/xc_course/doc/_mappingyigelizi: { "properties": { "name": { "type": "text" }, "description": { "type": "text" }, "studymodel": { "type": "keyword" } }}3、gengxinyingsheyingshechuangjianchenggongkeyitianjiaxinziduan,yiyouziduanbuyunxugengxin。4、shanchuyingshetongguoshanchusuoyinlaishanchuyingshe。changyongyingsheleixingtextwenbenziduanxiatushiES6.2hexindeziduanleixingruxia:zifuchuanbaokuotexthekeywordliangzhongleixing:1、text1)analyzertongguoanalyzershuxingzhidingfenciqi。xiabianzhidingnamedeziduanleixingweitext,shiyongikfenciqideik_max_wordfencimoshi。 "name": { "type": "text", "analyzer":"ik_max_word" }shangbianzhidingliaoanalyzershizhizaisuoyinhesousuodushiyongik_max_word,ruguodanduxiangdingyisousuoshishiyongdefenciqizekeyitongguosearch_analyzershuxing。duiyuikfenciqijianyishisuoyinshishiyongik_max_wordjiangsousuoneirongjinxingxilidufenci,sousuoshishiyongik_smarttigaosousuojingquexing。"name": { "type": "text", "analyzer":"ik_max_word", "search_analyzer":"ik_smart" }2)indextongguoindexshuxingzhidingshifousuoyin。morenweiindex=true,jiyaojinxingsuoyin,zhiyoujinxingsuoyincaikeyicongsuoyinkusousuodao。danshiyeyouyixieneirongbuxuyaosuoyin,biru:shangpintupiandizhizhibeiyonglaizhanshitupian,bujinxingsousuotupian,cishikeyijiangindexshezhiweifalse。shanchusuoyin,zhongxinchuangjianyingshe,jiangpicdeindexshezhiweifalse,changshigenjupicqusousuo,jieguosousuobudaoshuju "pic": { "type": "text", "index":false }3)storeshifouzaisourcezhiwaicunchu,meigewendangsuoyinhouhuizai ESzhongbaocunyifenyuanshiwendang,cunfangzai"_source"zhong,yibanqingkuangxiabuxuyaoshezhistoreweitrue,yinweizai_sourcezhongyijingyouyifenyuanshiwendangliao。ceshishanchuxc_course/docxiadeyingshechuangjianxinyingshe:Post http://localhost:9200/xc_course/doc/_mapping { "properties": { "name": { "type": "text", "analyzer":"ik_max_word", "search_analyzer":"ik_smart" }, "description": { "type": "text", "analyzer":"ik_max_word", "search_analyzer":"ik_smart" }, "pic":{ "type":"text", "index":false }, "studymodel":{ "type":"text" } }}charuwendang:http://localhost:9200/xc_course/doc/4028e58161bcf7f40161bcf8b77c0000{ "name":"Bootstrapkaifakuangjia", "description":"BootstrapshiyouTwittertuichudeyigeqiantaiyemiankaifakuangjia,zaixingyezhizhongshiyongjiaoweiguangfan。cikaifakuangjiabaohanliaodaliangdeCSS、JSchengxudaima,keyibangzhukaifazhe(youqishibushanchangyemiankaifadechengxurenyuan)qingsongdeshixianyigebushouzuolanqixianzhidejingmeijiemianxiaoguo。", "pic":"group1/M00/00/01/wKhlQFqO4MmAOP53AAAcwDwm6SU490.jpg", "studymodel":"201002"}chaxunceshi:Get http://localhost:9200/xc_course/_search?q=name:kaifaGet http://localhost:9200/xc_course/_search?q=description:kaifaGet http://localhost:9200/xc_course/_search?q=pic:group1/M00/00/01/wKhlQFqO4MmAOP53AAAcwDwm6SU490.jpgGet http://localhost:9200/xc_course/_search?q=studymodel:201002tongguoceshifaxian:namehedescriptionduzhichiquanwenjiansuo,picbukezuoweichaxuntiaojian。keywordguanjianziziduanshangbianjieshaodetextwenbenziduanzaiyingsheshiyaoshezhifenciqi,keywordziduanweiguanjianziziduan,tongchangsousuokeywordshianzhaozhengtisousuo,suoyichuangjiankeywordziduandesuoyinshishibujinxingfencide,biru:youzhengbianma、shoujihaoma、shenfenzhengdeng。keywordziduantongchangyongyuguolv、paixu、juhedeng。ceshigenggaiyingshe:{ "properties": { "studymodel":{ "type":"keyword" }, "name":{ "type":"keyword" } }}charuwendang:{ "name": "javabianchengjichu", "description": "javayuyanshishijiediyibianchengyuyan,zairuanjiankaifalingyushiyongrenshuzuiduo。", "pic":"group1/M00/00/01/wKhlQFqO4MmAOP53AAAcwDwm6SU490.jpg", "studymodel": "201001"}genjustudymodelchaxunwendangsousuo:http://localhost:9200/xc_course/_search?q=name:javanameshikeywordleixing,suoyichaxunfangshishijingquechaxun。dateriqileixingriqileixingbuyongshezhifenciqi。tongchangriqileixingdeziduanyongyupaixu。1)formattongguoformatshezhiriqigeshilizi:xiabiandeshezhiyunxudateziduancunchunianyuerishifenmiao、nianyuerijihaomiaosanzhonggeshi。{ "properties": { "timestamp": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd" } }}charuwendang:Post :http://localhost:9200/xc_course/doc/3{"name": "springkaifajichu","description": "spring zaijavalingyufeichangliuxing,javachengxuyuanduzaiyong。","studymodel": "201001", "pic":"group1/M00/00/01/wKhlQFqO4MmAOP53AAAcwDwm6SU490.jpg", "timestamp":"2018-07-04 18:28:58"}shuzhileixingxiabianshiESzhichideshuzhileixing1、jinliangxuanzefanweixiaodeleixing,tigaosousuoxiaolv2、duiyufudianshujinliangyongbiliyinzi,biruyigejiageziduan,danweiweiyuan,womenjiangbiliyinzishezhiwei100zhezaiESzhonghuian fen cunchu,yingsheruxia: "price": { "type": "scaled_float", "scaling_factor": 100 },youyubiliyinziwei100,ruguowomenshurudejiageshi23.45zeESzhonghuijiang23.45chengyi100cunchuzaiESzhong。ruguoshurudejiageshi23.456,EShuijiang23.456chengyi100zaiquyigejiejinyuanshizhideshu,dechu2346。shiyongbiliyinzidehaochushizhengxingbifudianxinggengyiyasuo,jieshengcipankongjian。ruguobiliyinzibushihe,zecongxiabiaoxuanzefanweixiaodequyong:gengxinyiyouyingshe,bingcharuwendang:http://localhost:9200/xc_course/doc/3{"name": "springkaifajichu","description": "spring zaijavalingyufeichangliuxing,javachengxuyuanduzaiyong。","studymodel": "201001", "pic":"group1/M00/00/01/wKhlQFqO4MmAOP53AAAcwDwm6SU490.jpg", "timestamp":"2018-07-04 18:28:58", "price":38.6}zonghelizichuangjianruxiayingshepost:http://localhost:9200/xc_course/doc/_mapping{ "properties": { "description": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "name": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "pic":{ "type":"text", "index":false }, "price": { "type": "float" }, "studymodel": { "type": "keyword" }, "timestamp": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } }charuwendang:Post: http://localhost:9200/xc_course/doc/1 { "name": "Bootstrapkaifa", "description": "BootstrapshiyouTwittertuichudeyigeqiantaiyemiankaifakuangjia,shiyigefeichangliuxingdekaifakuangjia,cikuangjiajichengliaoduozhongyemianxiaoguo。cikaifakuangjiabaohanliaodaliangdeCSS、JSchengxudaima,keyibangzhukaifazhe(youqishibushanchangyemiankaifadechengxurenyuan)qingsongdeshixianyigebushouzuolanqixianzhidejingmeijiemianxiaoguo。", "studymodel": "201002", "price":38.6, "timestamp":"2018-04-25 19:11:35", "pic":"group1/M00/00/00/wKhlQFs6RCeAY0pHAAJx5ZjNDEM428.jpg" }suoyinguanlidajiangongchengESkehuduanEStigongduozhongbutongdekehuduan:1、TransportClientEStigongdechuantongkehuduan,guanfangjihua8.0banbenshanchucikehuduan。2、RestClientRestClientshiguanfangtuijianshiyongde,tabaokuoliangzhong:Java Low Level REST Clienthe Java High Level REST Client。ESzai6.0zhihoutigong Java High Level REST Client, liangzhongkehuduanguanfanggengtuijianshiyong Java High Level REST Client,buguodangqiantahuanchuyuwanshanzhong,youxiegongnenghuanmeiyou。benjiaochengzhunbeicaiyong Java High Level REST Client,ruguotayoubuzhichidegongneng,zeshiyongJava Low Level REST Client。tianjiayilai: org.elasticsearch.client elasticsearch-rest-high-level-client 6.2.1 org.elasticsearch elasticsearch 6.2.1chuangjiansousuogongchengchuangjiansousuogongcheng(mavengongcheng):xc-service-search,tianjiaRestHighLevelClientyilaijijunityilai。pom.xml xc-framework-parent com.xuecheng 1.0-SNAPSHOT ../xc-framework-parent/pom.xml 4.0.0 xc-service-search com.xuecheng xc-framework-model 1.0-SNAPSHOT com.xuecheng xc-framework-common 1.0-SNAPSHOT com.xuecheng xc-service-api 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-web org.elasticsearch.client elasticsearch-rest-high-level-client 6.2.1 org.elasticsearch elasticsearch 6.2.1 org.springframework.boot spring-boot-starter-test test com.alibaba fastjson org.apache.commons commons-io org.apache.commons commons-lang3 2、peizhiwenjianapplication.ymlserver: port: ${port:40100}spring: application: name: xc-search-servicexuecheng: elasticsearch: hostlist: ${eshostlist:127.0.0.1:9200} #duogejiedianzhongjianyongdouhaofenge3、peizhileichuangjiancom.xuecheng.search.configbaozaiqixiachuangjianpeizhileipackage com.xuecheng.search.config;import org.apache.http.HttpHost;import org.elasticsearch.client.RestClient;import org.elasticsearch.client.RestHighLevelClient;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;@Configurationpublic class ElasticsearchConfig { @Value("${xuecheng.elasticsearch.hostlist}") private String hostlist; @Bean public RestHighLevelClient restHighLevelClient(){ //jiexihostlistpeizhixinxi String[] split = hostlist.split(","); //chuangjianHttpHostshuzu,qizhongcunfangeszhujiheduankoudepeizhixinxi HttpHost[] httpHostArray = new HttpHost[split.length]; for(int i=0;i jsonMap = new HashMap<>(); jsonMap.put("name", "spring cloudshizhan"); jsonMap.put("description", "benkechengzhuyaocongsigezhangjiejinxingjiangjie: 1.weifuwujiagourumen 2.spring cloud jichurumen 3.shizhanSpring Boot 4.zhucezhongxineureka。"); jsonMap.put("studymodel", "201001"); SimpleDateFormat dateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); jsonMap.put("timestamp", dateFormat.format(new Date())); jsonMap.put("price", 5.6f); //suoyinqingqiuduixiang IndexRequest indexRequest = new IndexRequest("xc_course","doc"); //zhidingsuoyinwendangneirong indexRequest.source(jsonMap); //suoyinxiangyingduixiang IndexResponse indexResponse = client.index(indexRequest); //huoquxiangyingjieguo DocWriteResponse.Result result = indexResponse.getResult(); System.out.println(result); }chaxunwendangAPIgeshiruxia: GET /{index}/{type}/{id}Java Client//chaxunwendang@Testpublic void getDoc() throws IOException { GetRequest getRequest = new GetRequest( "xc_course", "doc", "4028e581617f945f01617f9dabc40000"); GetResponse getResponse = client.get(getRequest); boolean exists = getResponse.isExists(); Map sourceAsMap = getResponse.getSourceAsMap(); System.out.println(sourceAsMap);}gengxinwendangApiESgengxinwendangdeshunxushi:xianjiansuodaowendang、jiangyuanlaidewendangbiaojiweishanchu、chuangjianxinwendang、shanchujiuwendang,chuangjianxinwendangjiuhuizhongjiansuoyin。tongguoqingqiuUrlyouliangzhongfangfa:1、wanquantihuanPost:http://localhost:9200/xc_test/doc/3 { "name":"spring cloudshizhan", "description":"benkechengzhuyaocongsigezhangjiejinxingjiangjie: 1.weifuwujiagourumen 2.spring cloud jichurumen 3.shizhanSpring Boot 4.zhucezhongxineureka。", "studymodel":"201001" "price":5.6 }2、jubugengxinxiabiandelizishizhigengxinpriceziduan。post: http://localhost:9200/xc_test/doc/3/_update{ "doc":{"price":66.6}}Java Clientshiyong Client Apigengxinwendangdefangfatongshangbiandierzhongjubugengxinfangfa。keyizhidingwendangdebufenziduanyekeyizhidingwanzhengdewendangneirong。 //gengxinwendang @Test public void updateDoc() throws IOException { UpdateRequest updateRequest = new UpdateRequest("xc_course", "doc", "4028e581617f945f01617f9dabc40000"); Map map = new HashMap<>(); map.put("name", "spring cloudshizhan"); updateRequest.doc(map); UpdateResponse update = client.update(updateRequest); RestStatus status = update.status(); System.out.println(status); }shanchuwendangApigenjuidshanchu,geshiruxia:DELETE /{index}/{type}/{id}sousuopipeishanchu,jiangsousuochulaidejilushanchu,geshiruxia:POST /{index}/{type}/_delete_by_queryxiabianshisousuotiaojianlizi:{ "query":{ "term":{ "studymodel":"201001" } }}shangbianlizidesousuopipeishanchuhuijiangstudymodelwei201001dejiluquanbushanchu。Java Client//genjuidshanchuwendang @Test public void testDelDoc() throws IOException { //shanchuwendangid String id = "eqP_amQBKsGOdwJ4fHiC"; //shanchusuoyinqingqiuduixiang DeleteRequest deleteRequest = new DeleteRequest("xc_course","doc",id); //xiangyingduixiang DeleteResponse deleteResponse = client.delete(deleteRequest); //huoquxiangyingjieguo DocWriteResponse.Result result = deleteResponse.getResult(); System.out.println(result); }sousuopipeishanchuhuanmeiyoujutideapi,keyicaiyongxiansousuochuwendangid,genjuwendangidshanchu。sousuoguanlizhunbeihuanjingchuangjianyingshechuangjianxc_coursesuoyinku。chuangjianruxiayingshepost:http://localhost:9200/xc_course/doc/_mappingcankao “ziliao”--》sousuoceshi-chushihuashuju.txt{ "properties": { "description": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "name": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "pic":{ "type":"text", "index":false }, "price": { "type": "float" }, "studymodel": { "type": "keyword" }, "timestamp": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } }charuyuanshishujuxiangxc_course/doczhongcharuyixiashuju:cankao “ziliao”--》sousuoceshi-chushihuashuju.txthttp://localhost:9200/xc_course/doc/1{"name": "Bootstrapkaifa","description": "BootstrapshiyouTwittertuichudeyigeqiantaiyemiankaifacsskuangjia,shiyigefeichangliuxingdekaifakuangjia,cikuangjiajichengliaoduozhongyemianxiaoguo。cikaifakuangjiabaohanliaodaliangdeCSS、JSchengxudaima,keyibangzhukaifazhe(youqishibushanchangcssyemiankaifadechengxurenyuan)qingsongdeshixianyigecss,bushouzuolanqixianzhidejingmeijiemiancssxiaoguo。","studymodel": "201002","price":38.6,"timestamp":"2018-04-25 19:11:35","pic":"group1/M00/00/00/wKhlQFs6RCeAY0pHAAJx5ZjNDEM428.jpg"}http://localhost:9200/xc_course/doc/2{"name": "javabianchengjichu","description": "javayuyanshishijiediyibianchengyuyan,zairuanjiankaifalingyushiyongrenshuzuiduo。","studymodel": "201001","price":68.6,"timestamp":"2018-03-25 19:11:35","pic":"group1/M00/00/00/wKhlQFs6RCeAY0pHAAJx5ZjNDEM428.jpg"}http://localhost:9200/xc_course/doc/3{"name": "springkaifajichu","description": "spring zaijavalingyufeichangliuxing,javachengxuyuanduzaiyong。","studymodel": "201001","price":88.6,"timestamp":"2018-02-24 19:11:35","pic":"group1/M00/00/00/wKhlQFs6RCeAY0pHAAJx5ZjNDEM428.jpg"}jiandansousuojiandansousuojiushitongguourljinxingchaxun,yigetfangshiqingqiuES。geshi:get ../_search?q=.....q:sousuozifuchuan。lizi:?q=name:spring sousuonamezhongbaokuospringdewendang。DSLsousuoDSL(Domain Specific Language)shiEStichudejiyujsondesousuofangshi,zaisousuoshichuanrutedingdejsongeshideshujulaiwanchengbutongdesousuoxuqiu。DSLbiURIsousuofangshigongnengqiangda,zaixiangmuzhongjianyishiyongDSLfangshilaiwanchengsousuo。chaxunsuoyouwendangchaxunsuoyousuoyinkudewendang。fasong:post http://localhost:9200/_searchchaxunzhidingsuoyinkuzhidingleixingxiadewendang。(tongguoshiyongcifangfa)fasong:post http://localhost:9200/xc_course/doc/_search{ "query": { "match_all": {} }, "_source" : ["name","studymodel"]}_source:sourceyuanguolvshezhi,zhidingjieguozhongsuobaokuodeziduanyounaxie。jieguoshuoming:took:bencicaozuohuafeideshijian,danweiweihaomiao。timed_out:qingqiushifouchaoshi_shards:shuomingbencicaozuogongsousuoliaonaxiefenpianhits:sousuomingzhongdejiluhits.total : fuhetiaojiandewendangzongshu hits.hits :pipeidujiaogaodeqianNgewendanghits.max_score:wendangpipeidefen,zheliweizuigaofen_score:meigewendangduyouyigepipeidudefen,anzhaojiangxupailie。_source:xianshiliaowendangdeyuanshineirong。JavaClient:@SpringBootTest@RunWith(SpringRunner.class)public class TestSearch { @Autowired RestHighLevelClient client; @Autowired RestClient restClient; //sousuotypexiadequanbujilu @Test public void testSearchAll() throws IOException, ParseException { //sousuoqingqiuduixiang SearchRequest searchRequest = new SearchRequest("xc_course"); //shezhileixing searchRequest.types("doc"); //sousuoyuangoujianduixiang SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); //sousuoquanbu searchSourceBuilder.query(QueryBuilders.matchAllQuery()); //sourceyuanziduanguolv searchSourceBuilder.fetchSource(new String[]{"name","studymodel","price","timestamp"},new String[]{}); //shezhisousuoyuan searchRequest.source(searchSourceBuilder); //zhixingsousuo SearchResponse searchResponse = client.search(searchRequest); //sousuopipeijieguo SearchHits hits = searchResponse.getHits(); //sousuozongjilushu long totalHits = hits.totalHits; //pipeidujiaogaodeqianNgewendang SearchHit[] searchHits = hits.getHits(); //riqigeshihuaduixiang SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for(SearchHit hit:searchHits){ //wendangid String id = hit.getId(); //yuanwendangneirong Map sourceAsMap = hit.getSourceAsMap(); //huoquyuanwendangname String name = (String) sourceAsMap.get("name"); String description = (String) sourceAsMap.get("description"); String studymodel = (String) sourceAsMap.get("studymodel"); Double price = (Double) sourceAsMap.get("price"); Date timestamp = dateFormat.parse((String) sourceAsMap.get("timestamp")); System.out.println(name); System.out.println(studymodel); System.out.println(description); } } ....fenyechaxunESzhichifenyechaxun,chuanrulianggecanshu:fromhesize。form:biaoshiqishiwendangdexiabiao,cong0kaishi。size:chaxundewendangshuliang。fasong:post http://localhost:9200/xc_course/doc/_search{"from" : 0, "size" : 1,"query": { "match_all": {} },"_source" : ["name","studymodel"]}JavaClient...SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();//shezhifenyecanshu//dangqianyemaint page = 2;//yemaint size = 1;//meiyexianshigeshuint from = (page - 1) * size;//qijiluxiabiaosearchSourceBuilder.from(from);searchSourceBuilder.size(size);...Term QueryTerm Queryweijingquechaxun,zaisousuoshihuizhengtipipeiguanjianzi,buzaijiangguanjianzifenci。fasong:post http://localhost:9200/xc_course/doc/_search{ "query": { "term" : { "name": "spring" } }, "_source" : ["name","studymodel"] }shangbiandesousuohuichaxunnamebaokuo“spring”zhegecidewendang。JavaClient:...//sousuoqingqiuduixiangSearchRequest searchRequest = new SearchRequest("xc_course");//shezhileixingsearchRequest.types("doc");//sousuoyuangoujianduixiangSearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();//TermQuerysearchSourceBuilder.query(QueryBuilders.termQuery("name","spring"));//sourceyuanziduanguolvsearchSourceBuilder.fetchSource(new String[]{"name","studymodel","price","timestamp"},new String[]{});//shezhisousuoyuansearchRequest.source(searchSourceBuilder);//zhixingsousuoSearchResponse searchResponse = client.search(searchRequest);...genjuidjingquepipeiEStigonggenjuduogeidzhipipeidefangfa:ceshi:post: http://127.0.0.1:9200/xc_course/doc/_search{ "query": { "ids" : { "type" : "doc", "values" : ["3", "4", "100"] } }}JavaClient:tongguotermsQueryjinxingchaxun,daimaruxia://sousuoqingqiuduixiangSearchRequest searchRequest = new SearchRequest("xc_course");//shezhileixingsearchRequest.types("doc");//sousuoyuangoujianduixiangSearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();//zhujianString[] ids = new String[]{"1","2"};//TermQuerysearchSourceBuilder.query(QueryBuilders.termsQuery("_id", ids));//sourceyuanziduanguolvsearchSourceBuilder.fetchSource(new String[]{"name","studymodel","price","timestamp"},new String[]{});//shezhisousuoyuansearchRequest.source(searchSourceBuilder);//zhixingsousuoSearchResponse searchResponse = client.search(searchRequest);match Query1、jibenshiyongmatch Queryjiquanwenjiansuo,tadesousuofangshishixianjiangsousuozifuchuanfenci,zaishiyonggegecitiaocongsuoyinzhongsousuo。match queryyuTerm queryqubieshimatch queryzaisousuoqianxianjiangsousuoguanjianzifenci,zainagegeciyuqusuoyinzhongsousuo。fasong:post http://localhost:9200/xc_course/doc/_search{ "query": { "match" : { "description" : { "query" : "springkaifa", "operator" : "or" } } }}query:sousuodeguanjianzi,duiyuyingwenguanjianziruguoyouduogedancizezhongjianyaoyongbanjiaodouhaofenge,erduiyuzhongwenguanjianzizhongjiankeyiyongdouhaofengeyekeyibuyong。operator:or biaoshi zhiyaoyouyigecizaiwendangzhongchuxianzejiufuhetiaojian,andbiaoshimeigeciduzaiwendangzhongchuxianzecaifuhetiaojian。shangbiandesousuodezhixingguochengshi:1、jiang“springkaifa”fenci,fenweispring、kaifalianggeci2、zaishiyongspringhekaifalianggeciqupipeisuoyinzhongsousuo。3、youyushezhiliaooperatorweior,zhiyaoyouyigecipipeichenggongzejiufanhuigaiwendang。JavaClient://genjuguanjianzisousuo@Test public void testMatchQuery() throws IOException, ParseException { //sousuoqingqiuduixiang SearchRequest searchRequest = new SearchRequest("xc_course"); //shezhileixing searchRequest.types("doc"); //sousuoyuangoujianduixiang SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); //MatcherQuery searchSourceBuilder.query(QueryBuilders.matchQuery("description","springkaifa").operator(Operator.OR)); //sourceyuanziduanguolv searchSourceBuilder.fetchSource(new String[]{"name","studymodel","price","timestamp"},new String[]{}); //shezhisousuoyuan searchRequest.source(searchSourceBuilder); //zhixingsousuo SearchResponse searchResponse = client.search(searchRequest); //sousuopipeijieguo SearchHits hits = searchResponse.getHits(); //sousuozongjilushu long totalHits = hits.totalHits; //pipeidujiaogaodeqianNgewendang SearchHit[] searchHits = hits.getHits(); //riqigeshihuaduixiang SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for(SearchHit hit:searchHits){ //wendangid String id = hit.getId(); //yuanwendangneirong Map sourceAsMap = hit.getSourceAsMap(); //huoquyuanwendangname String name = (String) sourceAsMap.get("name"); String description = (String) sourceAsMap.get("description"); String studymodel = (String) sourceAsMap.get("studymodel"); Double price = (Double) sourceAsMap.get("price"); Date timestamp = dateFormat.parse((String) sourceAsMap.get("timestamp")); System.out.println(name); System.out.println(studymodel); System.out.println(description); } }2、minimum_should_matchshangbianshiyongdeoperator = orbiaoshizhiyaoyouyigecipipeishangjiudefen,ruguoshixiansangecizhishaoyoulianggecipipeiruheshixian?shiyongminimum_should_matchkeyizhidingwendangpipeicidezhanbi:birusousuoyujuruxia:{ "query": { "match" : { "description" : { "query" : "springkaifakuangjia", "minimum_should_match": "80%" } } }}“springkaifakuangjia”huibeifenweisangeci:spring、kaifa、kuangjiashezhi"minimum_should_match": "80%"biaoshi,sangecizaiwendangdepipeizhanbiwei80%,ji3*0.8=2.4,xiangshangquzhengde2,biaoshizhishaoyoulianggecizaiwendangzhongyaopipeichenggong。duiyingdeRestClientruxia://MatcherQuery searchSourceBuilder.query(QueryBuilders.matchQuery("description","springkaifakuangjia") .operator(Operator.OR) .minimumShouldMatch("80%")); multi QueryshangbianxuexidetermQueryhematchQueryyicizhinengpipeiyigeField,benjiexueximultiQuery,yicikeyipipeiduogeziduan。1、jibenshiyongdanxiangpipeishizaiyigefieldzhongqupipei,duoxiangpipeishinaguanjianziquduogeFieldzhongpipei。lizi:fasong:post http://localhost:9200/xc_course/doc/_searchnaguanjianzi “spring css”qupipeiname hedescriptionziduan。{ "query": { "multi_match" : { "query" : "spring css", "minimum_should_match": "50%", "fields": [ "name", "description" ] } }}2、tishengboostpipeiduogeziduanshikeyitishengziduandeboost(quanzhong)laitigaodefenlizi:tishengboostzhiqian,zhixingxiabiandechaxun:{ "query": { "multi_match" : { "query" : "spring css", "minimum_should_match": "50%", "fields": [ "name", "description" ] } }}tongguochaxunfaxianBootstrappaizaiqianbian。tishengboost,tongchangguanjianzipipeishangnamedequanzhongyaobipipeishangdescriptiondequanzhonggao,zhelikeyiduinamedequanzhongtisheng。{ "query": { "multi_match" : { "query" : "spring css", "minimum_should_match": "50%", "fields": [ "name^10", "description" ] } }}“name^10” biaoshiquanzhongtisheng10bei,zhixingshangbiandechaxun,faxiannamezhongbaokuospringguanjianzidewendangpaizaiqianbian。JavaClient://sousuoyuangoujianduixiangSearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();//MultiMatcherQueryMultiMatchQueryBuilder matchQueryBuilder = QueryBuilders.multiMatchQuery("spring css", "name", "description") .minimumShouldMatch("50%") .field("name", 10);searchSourceBuilder.query(matchQueryBuilder);buerchaxunbuerchaxunduiyingyuLucenedeBooleanQuerychaxun,shixianjiangduogechaxunzuheqilai。sangecanshu:must:wendangbixupipeimustsuobaokuodechaxuntiaojian,xiangdangyu “AND” should:wendangyinggaipipeishouldsuobaokuodechaxuntiaojianqizhongdeyigehuoduoge,xiangdangyu "OR" must_not:wendangbunengpipeimust_notsuobaokuodegaichaxuntiaojian,xiangdangyu“NOT”fenbieshiyongmust、should、must_notceshixiabiandechaxun:fasong:POST http://localhost:9200/xc_course/doc/_search{ "_source" : [ "name", "studymodel", "description"], "from" : 0, "size" : 1, "query": { "bool" : { "must":[ { "multi_match" : { "query" : "spring css", "minimum_should_match": "50%", "fields": [ "name^10", "description" ] } }, { "term":{ "studymodel" : "201001" } } ] } }}must:biaoshibixu,duogechaxuntiaojianbixudumanzu。(tongchangshiyongmust)should:biaoshihuozhe,duogechaxuntiaojianzhiyaoyouyigemanzujike。must_not:biaoshifei。JavaClient://BoolQuery,jiangsousuoguanjianzifenci,nafenciqusuoyinkusousuo//sousuoyuangoujianduixiangSearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();//MultiMatcherQueryMultiMatchQueryBuilder matchQueryBuilder = QueryBuilders.multiMatchQuery("spring css", "name", "description") .minimumShouldMatch("50%") .field("name", 10);//TermQueryTermQueryBuilder termQueryBuilder = QueryBuilders.termQuery("studymodel", "201001");//boolQueryBuilderBoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();//jiangMultiMatcherQueryheTermQueryzuzhizaiyiqiboolQueryBuilder.must(matchQueryBuilder);boolQueryBuilder.must(termQueryBuilder);searchSourceBuilder.query(boolQueryBuilder);guolvqiguolvshizhenduisousuodejieguojinxingguolv,guolvqizhuyaopanduandeshiwendangshifoupipei,buqujisuanhepanduanwendangdepipeidudefen,suoyiguolvqixingnengbichaxunyaogao,qiefangbianhuancun,tuijianjinliangshiyongguolvqiqushixianchaxunhuozheguolvqihechaxungongtongshiyong。guolvqizaibuerchaxunzhongshiyong,xiabianshizaisousuojieguodejichushangjinxingguolv:{ "_source" : [ "name", "studymodel", "description","price"], "query": { "bool" : { "must":[ { "multi_match" : { "query" : "spring css", "minimum_should_match": "50%", "fields": [ "name^10", "description" ] } } ], "filter": [ { "term": { "studymodel": "201001" }}, { "range": { "price": { "gte": 60 ,"lte" : 100}}} ] } }}range:fanweiguolv,baoliudayudengyu60 bingqiexiaoyudengyu100dejilu。term:xiangpipeiguolv,baoliustudymodeldengyu"201001"dejilu。zhuyi:rangehetermyicizhinengduiyigeFieldshezhifanweiguolv。client://sousuoyuangoujianduixiangSearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();//MultiMatcherQueryMultiMatchQueryBuilder matchQueryBuilder = QueryBuilders.multiMatchQuery("spring css", "name", "description") .minimumShouldMatch("50%") .field("name", 10);//boolQueryBuilderBoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();//jiangMultiMatcherQueryheTermQueryzuzhizaiyiqiboolQueryBuilder.must(matchQueryBuilder);//tianjiaguolvqi//xiangguolvboolQueryBuilder.filter(QueryBuilders.termQuery("studymodel","201001"));//fanweiguolvboolQueryBuilder.filter(QueryBuilders.rangeQuery("price").gte(60).lte(100));searchSourceBuilder.query(boolQueryBuilder);paixukeyizaiziduanshangtianjiayigehuoduogepaixu,zhichizaikeyword、date、floatdengleixingshangtianjia,textleixingdeziduanshangbuyunxutianjiapaixu。fasong POST http://localhost:9200/xc_course/doc/_searchguolv0--10yuanjiagefanweidewendang,bingqieduijieguojinxingpaixu,xiananstudymodeljiangxu,zaianjiageshengxu{ "_source" : [ "name", "studymodel", "description","price"], "query": { "bool" : { "filter": [ { "range": { "price": { "gte": 0 ,"lte" : 100}}} ] } }, "sort" : [ { "studymodel" : "desc" }, { "price" : "asc" } ]}client:@Testpublic void testSort() throws IOException, ParseException { //sousuoqingqiuduixiang SearchRequest searchRequest = new SearchRequest("xc_course"); //shezhileixing searchRequest.types("doc"); //sousuoyuangoujianduixiang SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); //sourceyuanziduanguolv searchSourceBuilder.fetchSource(new String[]{"name","studymodel","price","timestamp"},new String[]{}); //boolQueryBuilder BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); //tianjiaguolvqi //fanweiguolv boolQueryBuilder.filter(QueryBuilders.rangeQuery("price").gte(0).lte(100)); searchSourceBuilder.query(boolQueryBuilder); //shezhisousuoyuan searchRequest.source(searchSourceBuilder); //shezhipaixu searchSourceBuilder.sort("studymodel", SortOrder.DESC); searchSourceBuilder.sort("price", SortOrder.ASC); //zhixingsousuo SearchResponse searchResponse = client.search(searchRequest); //sousuopipeijieguo SearchHits hits = searchResponse.getHits(); //sousuozongjilushu long totalHits = hits.totalHits; //pipeidujiaogaodeqianNgewendang SearchHit[] searchHits = hits.getHits(); //riqigeshihuaduixiang SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for(SearchHit hit:searchHits){ //wendangid String id = hit.getId(); //yuanwendangneirong Map sourceAsMap = hit.getSourceAsMap(); //huoquyuanwendangname String name = (String) sourceAsMap.get("name"); String description = (String) sourceAsMap.get("description"); String studymodel = (String) sourceAsMap.get("studymodel"); Double price = (Double) sourceAsMap.get("price"); Date timestamp = dateFormat.parse((String) sourceAsMap.get("timestamp")); System.out.println(name); System.out.println(studymodel); System.out.println(description); }}gaoliangxianshigaoliangxianshikeyijiangsousuojieguoyigehuoduogezituchuxianshi,yibianxiangyonghuzhanshipipeiguanjianzideweizhi。zaisousuoyujuzhongtianjiahighlightjikeshixian,ruxia:Post: http://127.0.0.1:9200/xc_course/doc/_search{ "_source" : [ "name", "studymodel", "timestamp","price"], "query": { "bool" : { "must":[ { "multi_match" : { "query" : "kaifakuangjia", "minimum_should_match": "50%", "fields": [ "name^10", "description" ] } } ], "filter": [ { "range": { "price": { "gte": 0 ,"lte" : 100}}} ] } }, "sort" : [ { "price" : "asc" } ], "highlight": { "pre_tags": [""], "post_tags": [""], "fields": { "name": {}, "description":{} } }}clientdaimaruxia:@Testpublic void testHighLight() throws IOException, ParseException { //sousuoqingqiuduixiang SearchRequest searchRequest = new SearchRequest("xc_course"); //shezhileixing searchRequest.types("doc"); //sousuoyuangoujianduixiang SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); //sourceyuanziduanguolv searchSourceBuilder.fetchSource(new String[]{"name","studymodel","price","timestamp"},new String[]{}); //MultiMatcherQuery MultiMatchQueryBuilder matchQueryBuilder = QueryBuilders.multiMatchQuery("kaifakuangjia", "name", "description") .minimumShouldMatch("80%") .field("name", 10); //boolQueryBuilder BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); boolQueryBuilder.must(matchQueryBuilder); //tianjiaguolvqi //fanweiguolv boolQueryBuilder.filter(QueryBuilders.rangeQuery("price").gte(0).lte(100)); searchSourceBuilder.query(boolQueryBuilder); //shezhisousuoyuan searchRequest.source(searchSourceBuilder); //shezhipaixu searchSourceBuilder.sort("studymodel", SortOrder.DESC); searchSourceBuilder.sort("price", SortOrder.ASC); //shezhigaoliang HighlightBuilder highlightBuilder = new HighlightBuilder(); highlightBuilder.preTags(""); highlightBuilder.postTags(""); highlightBuilder.fields().add(new HighlightBuilder.Field("name")); searchSourceBuilder.highlighter(highlightBuilder); //zhixingsousuo SearchResponse searchResponse = client.search(searchRequest); //sousuopipeijieguo SearchHits hits = searchResponse.getHits(); //sousuozongjilushu long totalHits = hits.totalHits; //pipeidujiaogaodeqianNgewendang SearchHit[] searchHits = hits.getHits(); //riqigeshihuaduixiang SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for(SearchHit hit:searchHits){ //wendangid String id = hit.getId(); //yuanwendangneirong Map sourceAsMap = hit.getSourceAsMap(); //huoquyuanwendangname String name = (String) sourceAsMap.get("name"); //quchugaoliangziduan Map highlightFields = hit.getHighlightFields(); if(highlightFields!=null){ //quchunamegaoliangziduan HighlightField nameField = highlightFields.get("name"); if(nameField!=null){ Text[] fragments = nameField.fragments(); StringBuffer stringBuffer = new StringBuffer(); for(Text text:fragments){ stringBuffer.append(text); } name = stringBuffer.toString(); } } String description = (String) sourceAsMap.get("description"); String studymodel = (String) sourceAsMap.get("studymodel"); Double price = (Double) sourceAsMap.get("price"); Date timestamp = dateFormat.parse((String) sourceAsMap.get("timestamp")); System.out.println(name); System.out.println(studymodel); System.out.println(description); }}jiqunguanlijiqunjiegouEStongchangyijiqunfangshigongzuo,zheyangzuobujinnenggoutigao ESdesousuonenglihuankeyichulidashujusousuodenengli,tongshiyezengjialiaoxitongderongcuonenglijigaokeyong,ESkeyishixianPBjishujudesousuo。xiatushiESjiqunjiegoudeshiyitu:congshangtuzongjieyixiagainian:1、jiedianESjiqunyouduogefuwuqizucheng,meigefuwuqijiweiyigeNodejiedian(gaifuwuzhibushuliaoyigeESjincheng)。2、fenpiandangwomendewendanglianghendashi,youyuneicunheyingpandexianzhi,tongshiyeweiliaotigaoESdechulinengli、rongcuonenglijigaokeyongnengli,womenjiangsuoyinfenchengruoganfenpian,meigefenpiankeyifangzaibutongdefuwuqi,zheyangjiushixianliaoduogefuwuqigongtongduiwaitigongsuoyinjisousuofuwu。yigesousuoqingqiuguolai,huifenbieconggegefenpianquchaxun,zuihoujiangchaxundaodeshujuhebingfanhuigeiyonghu。3、fubenweiliaotigaoESdegaokeyongtongshiyeweiliaotigaosousuodetuntuliang,womenjiangfenpianfuzhiyifenhuoduofencunchuzaiqitadefuwuqi,zheyangjishidangqiandefuwuqiguadiaoliao,yongyoufubendefuwuqizhaochangkeyitigongfuwu。4、zhujiedianyigejiqunzhonghuiyouyigehuoduogezhujiedian,zhujiediandezuoyongshijiqunguanli,biruzengjiajiedian,yichujiediandeng,zhujiedianguadiaohouEShuizhongxinxuanyigezhujiedian。5、jiedianzhuanfameigejiedianduzhidaoqitajiediandexinxi,womenkeyiduirenyiyigejiedianfaqiqingqiu,jieshouqingqiudejiedianhuizhuanfageiqitajiedianchaxunshuju。dajianjiqunxiabiandelizishixianchuangjianyige2jiediandejiqun,bingqiesuoyindefenpianwomenshezhi2pian,meipianyigefuben。jiediandesangejiaosezhujiedian:masterjiedianzhuyaoyongyujiqundeguanlijisuoyin biruxinzengjiedian、fenpianfenpei、suoyindexinzengheshanchudeng。 shujujiedian:data jiedianshangbaocunliaoshujufenpian,tafuzesuoyinhesousuocaozuo。 kehuduanjiedian:client jiedianjinzuoweiqingqiukehuduancunzai,clientdezuoyongyezuoweifuzaijunhengqi,client jiedianbucunshuju,zhishijiangqingqiujunhengzhuanfadaoqitajiedian。tongguoxiabianliangxiangcanshulaipeizhijiediandegongneng:node.master: #shifouyunxuweizhujiediannode.data: #yunxucunchushujuzuoweishujujiediannode.ingest: #shifouyunxuchengweixiediaojiedian,sizhongzuhefangshi:master=true,data=true:jishizhujiedianyoushishujujiedianmaster=false,data=true:jinshishujujiedianmaster=true,data=false:jinshizhujiedian,bucunchushujumaster=false,data=false:jibushizhujiedianyebushishujujiedian,cishikeshezhiingestweitruebiaoshitashiyigekehuduan。chuangjianjiedian 1jieyaelasticsearch-6.2.1.zip dao F:\devenv\elasticsearch\es-cloud-1\elasticsearch-6.2.1jiedian1duiwaifuwudehttpduankoushi:9200jiqunguanliduankoushi9300peizhielasticsearch.ymljiedianming:xc_node_1elasticsearch.ymlneirongruxiacluster.name: xuechengnode.name: xc_node_1network.host: 0.0.0.0http.port: 9200transport.tcp.port: 9300node.master: truenode.data: truediscovery.zen.ping.unicast.hosts: ["0.0.0.0:9300", "0.0.0.0:9301"]discovery.zen.minimum_master_nodes: 1node.ingest: truenode.max_local_storage_nodes: 2path.data: D:\ElasticSearch\elasticsearch-6.2.1-1\datapath.logs: D:\ElasticSearch\elasticsearch-6.2.1-1\logshttp.cors.enabled: truehttp.cors.allow-origin: /.*/qidongjiedian1chuangjianjiedian 2jieyaelasticsearch-6.2.1.zip dao F:\devenv\elasticsearch\es-cloud-2\elasticsearch-6.2.1jiedian1duiwaifuwudehttpduankoushi:9201jiqunguanliduankoushi9301jiedianming:xc_node_2elasticsearch.ymlneirongruxiacluster.name: xuechengnode.name: xc_node_2network.host: 0.0.0.0http.port: 9201transport.tcp.port: 9301node.master: truenode.data: truediscovery.zen.ping.unicast.hosts: ["0.0.0.0:9300", "0.0.0.0:9301"]discovery.zen.minimum_master_nodes: 1node.ingest: truenode.max_local_storage_nodes: 2path.data: D:\ElasticSearch\elasticsearch-6.2.1-2\datapath.logs: D:\ElasticSearch\elasticsearch-6.2.1-2\logshttp.cors.enabled: truehttp.cors.allow-origin: /.*/qidongjiedian2chuangjiansuoyinku1)shiyongheadlianshangqizhongyigejiedianshangtubiaoshilianggejiedianyijingchuangjianchenggong。2)xiabianchuangjiansuoyinku,gong2gefenpian,meigefenpianyigefuben。chuangjianchenggong,shuaxinhead:shangtukeyikandaogongyou4gefenpian,qizhonglianggefenpianshifuben。3)meigejiediananzhuangIKfenciqiluejiqundejiankangtongguofangwen GET /_cluster/health laichakanElasticsearch dejiqunjiankangqingkuang。yongsanzhongyanselaizhanshijiankangzhuangtai: green 、 yellow huozhe red 。green:suoyoudezhufenpianhefubenfenpianduzhengchangyunxing。 yellow:suoyoudezhufenpianduzhengchangyunxing,danyouxiefubenfenpianyunxingbuzhengchang。 red:cunzaizhufenpianyunxingbuzhengchang。Getqingqiu:http://localhost:9200/_cluster/healthxiangyingjieguo:{ "cluster_name": "xuecheng", "status": "green", "timed_out": false, "number_of_nodes": 2, "number_of_data_nodes": 2, "active_primary_shards": 2, "active_shards": 4, "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 0, "delayed_unassigned_shards": 0, "number_of_pending_tasks": 0, "number_of_in_flight_fetch": 0, "task_max_waiting_in_queue_millis": 0, "active_shards_percent_as_number": 100}ceshi1)chuangjianyingshebingxieruwendanglianjie qizhongrenyiyitaijiedian,chuangjianyingshexieruwendang。Post http://localhost:9200/xc_course/doc/3{"name": "springkaifajichu","description": "spring zaijavalingyufeichangliuxing,javaruanjiankaifarenyuanduzaiyong。","studymodel": "201001","price":66.6}xiangyingjieguo:{ "_index": "xc_course", "_type": "doc", "_id": "3", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 2, "failed": 0 }, "_seq_no": 0, "_primary_term": 1}congshangbiandetishikekanchu,lianggefenpiandubaocunchenggong。2)sousuoxiangqitayigejiedianfaqisousuoqingqiu,chaxunquanbushuju。3)guanbiyigejiedianEShuizhongxinxuanzhongyigezhujiedian(qiantizaipeizhijiedianshiyunxutakeyiweizhujiedian)cishixianghuodejiedianfaqisousuoqingqiu,rengranzhengchang。4)tianjiayigejiediantianjiajiedian3,duankoushezhiwei:httpduankoushi:9202jiqunguanliduankoushi9302jiedianming:xc_node_3cijiediandepeizhi:node.master: false node.data: trueqidongjiedian3,shuaxinhead,xiatuxianshiESjiangfenpianjifubenjunyunfenzailiao3gejiedian(zhuyihuanjingbutongfenbudejieguokenengbutong)xiangjiedian3faqisousuoqingqiu:Get: http://127.0.0.1:9202/xc_course/doc/_searchquanbushujukebeizhengchangsousuodao。weishenrutuidongshubianpeizhinengyunweishuipingyunenglitisheng,guizhoudianwanggongsizongticong“yunweizhinengcehua、yunxingzhinengxunjian、shujuzhinengfenxi、zuoyezhinengcaozuo、anquanzhinengguankong,fengxianzhihuifangkong”liugefangmiankaizhanguihua,chengliliaozhinengzuoyezhongxin,quanmiantuidongshudianxianluxunjianshuzihua、zhinenghuatisheng。
于(Yu)是(Shi)母(Mu)亲(Qin)便(Bian)开(Kai)启(Qi)了(Liao)长(Chang)达(Da)三(San)四(Si)年(Nian)的(De)调(Diao)理(Li)身(Shen)体(Ti)生(Sheng)活(Huo),每(Mei)天(Tian)都(Du)要(Yao)喝(He)那(Na)难(Nan)闻(Wen)又(You)苦(Ku)的(De)不(Bu)行(Xing)的(De)中(Zhong)药(Yao)汤(Tang),但(Dan)一(Yi)直(Zhi)都(Du)没(Mei)有(You)什(Shi)么(Me)起(Qi)色(Se)。
keyikandao,yanxuwendingdefenhongfengge,duojiashangshiyinxingnipaixianguimochixuchuangshangshiyilaixingao,meigugulijiaoshangnianyebuduantisheng,gengyou14jiayinxingdeguxilvzai5%yishang,duojiafenhongbilibaochizai30%jiyishang。zuozhe:buluofenzhanshi
迅(Xun)捷(Jie)兴(Xing):高(Gao)新(Xin)投(Tou)投(Tou)资(Zi)、人(Ren)才(Cai)二(Er)号(Hao)基(Ji)金(Jin)拟(Ni)减(Jian)持(Chi)不(Bu)超(Chao)3%股(Gu)份(Fen)
而且花露水的香味不仅能驱赶蚊虫,还能在家中留下清新的气息,去除掉异味。这种风气不仅降低了娱乐圈的整体形象,也在一定程度上对“饭圈文化”产生了负面影响。粉丝们过度关注明星的肉体,而忽视了他们的演技和艺术才华。《红蝴蝶在线视频免费观看》高清电影手机免费观看...
加一条经济压力不大的前提你说那些才成立
声明:该文观点仅代表作者本人,搜狐号系信息发布平台,搜狐仅提供信息存储空间服务。