銆屾壂鐩层€?Elasticsearch

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了銆屾壂鐩层€?Elasticsearch相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e4%b8%8d%e5%90%8c%e7%9a%84' title='涓嶅悓鐨?>涓嶅悓鐨?/a>   缁撳悎   纾佺洏   淇濆瓨   鍒嗙粍   鏂瑰紡   鍗曡瘝   鏂囩珷   cti   

浠€涔堟槸Elasticsearch锛?/h1>

Elasticsearch is a real-time, distributed storage, search, and analytics engine
Elasticsearch 鏄竴涓疄鏃剁殑鍒嗗竷寮忓瓨鍌ㄣ€佹悳绱€佸垎鏋愮殑寮曟搸銆?/p>

浠嬬粛閭e効鏈夊嚑涓叧閿瓧锛?br /> 瀹炴椂銆佸垎甯冨紡銆佹悳绱€佸垎鏋?/p>

浜庢槸鎴戜滑灏卞緱鐭ラ亾Elasticsearch鏄€庝箞鍋氬埌瀹炴椂鐨勶紝Elasticsearch鐨勬灦鏋勬槸鎬庝箞鏍风殑锛堝垎甯冨紡锛夈€傚瓨鍌ㄣ€佹悳绱㈠拰鍒嗘瀽锛堝緱鐭ラ亾Elasticsearch鏄€庝箞瀛樺偍銆佹悳绱㈠拰鍒嗘瀽鐨勶級

涓轰粈涔堣鐢‥lasticsearch

鍦ㄥ涔犱竴椤规妧鏈箣鍓嶏紝蹇呴』鍏堣浜嗚В涓轰粈涔堣浣跨敤杩欓」鎶€鏈€傛墍浠ワ紝涓轰粈涔堣浣跨敤Elasticsearch鍛紵鎴戜滑鍦ㄦ棩甯稿紑鍙戜腑锛屾暟鎹簱涔熻兘鍋氬埌锛堝疄鏃躲€佸瓨鍌ㄣ€佹悳绱€佸垎鏋愶級銆?/p>

鐩稿浜庢暟鎹簱锛孍lasticsearch鐨勫己澶т箣澶勫氨鏄彲浠ユā绯婃煡璇€?/p>

鏈夌殑鍚屽鍙兘灏变細璇达細鎴戞暟鎹簱鎬庝箞灏变笉鑳芥ā绯婃煡璇簡锛燂紵鎴戝弽鎵嬪氨缁欎綘鍐欎竴涓猄QL锛?br /> select * from user where name like 鈥?鍏紬鍙稪ava%鈥?br /> 杩欎笉灏卞彲浠ユ妸鍏紬鍙稪ava鐩稿叧鐨勫唴瀹规悳绱㈠嚭鏉ヤ簡鍚楋紵

鐨勭‘锛岃繖鏍峰仛鐨勭‘鍙互銆備絾鏄鏄庣櫧鐨勬槸锛歯ame like %Java%杩欑被鐨勬煡璇㈡槸涓嶈蛋绱㈠紩鐨勶紝涓嶈蛋绱㈠紩鎰忓懗鐫€锛氬彧瑕佷綘鐨勬暟鎹簱鐨勯噺寰堝ぇ锛?浜挎潯锛夛紝浣犵殑鏌ヨ鑲畾浼氭槸绉掔骇鍒殑

鑰屼笖锛屽嵆渚跨粰浣犱粠鏁版嵁搴撴牴鎹ā绯婂尮閰嶆煡鍑虹浉搴旂殑璁板綍浜嗭紝閭e線寰€浼氳繑鍥炲ぇ閲忕殑鏁版嵁缁欎綘锛屽線寰€浣犻渶瑕佺殑鏁版嵁閲忓苟娌℃湁杩欎箞澶氾紝鍙兘50鏉¤褰曞氨瓒冲浜嗐€?/p>

杩樻湁涓€涓氨鏄細鐢ㄦ埛杈撳叆鐨勫唴瀹瑰線寰€骞舵病鏈夎繖涔堢殑绮剧‘锛屾瘮濡傛垜浠嶨oogle杈撳叆ElastcSeach锛堟墦閿欏瓧锛夛紝浣嗘槸Google杩樻槸鑳戒及绠楁垜鎯宠緭鍏ョ殑鏄疎lasticsearch

鑰孍lasticsearch鏄笓闂ㄥ仛鎼滅储鐨勶紝灏辨槸涓轰簡瑙e喅涓婇潰鎵€璁茬殑闂鑰岀敓鐨勶紝鎹㈠彞璇濊锛?/p>

Elasticsearch瀵规ā绯婃悳绱㈤潪甯告搮闀匡紙鎼滅储閫熷害寰堝揩锛?/p>

浠嶦lasticsearch鎼滅储鍒扮殑鏁版嵁鍙互鏍规嵁璇勫垎杩囨护鎺夊ぇ閮ㄥ垎鐨勶紝鍙杩斿洖璇勫垎楂樼殑缁欑敤鎴峰氨濂戒簡锛堝師鐢熷氨鏀寔鎺掑簭锛?/p>

娌℃湁閭d箞鍑嗙‘鐨勫叧閿瓧涔熻兘鎼滃嚭鐩稿叧鐨勭粨鏋滐紙鑳藉尮閰嶆湁鐩稿叧鎬х殑璁板綍锛?/p>

涓嬮潰鎴戜滑灏辨潵瀛﹀涓轰粈涔圗lasticsearch鍙互鍋氬埌涓婇潰鐨勫嚑鐐广€?/p>


http://img.blog.itpub.net/blog/2020/01/15/ec0abd31539b7b77.jpeg?x-oss-process=style/bb

鍒嗚瘝

棣栧厛鎴戜滑寰楃煡閬撲负浠€涔圗lasticsearch涓轰粈涔堝彲浠ュ疄鐜板揩閫熺殑鈥滄ā绯婂尮閰嶁€?鈥滅浉鍏虫€ф煡璇⑩€濓紝瀹為檯涓婃槸浣犲啓鍏ユ暟鎹埌Elasticsearch鐨勬椂鍊欎細杩涜鍒嗚瘝銆?/p>

杩樻槸浠ヤ笂鍥句负渚嬶紝涓婂浘鍑虹幇浜?娆♀€滅畻娉曗€濊繖涓瘝锛屾垜浠兘涓嶈兘鏍规嵁杩欐璇嶄负瀹冩壘浠栧搴旂殑鐩綍锛烢lasticsearch姝f槸杩欐牱骞茬殑锛屽鏋滄垜浠牴鎹笂鍥炬潵鍋氳繖涓簨锛屼細寰楀埌绫讳技杩欐牱鐨勭粨鏋滐細

绠楁硶 ->2,13,42,56

杩欎唬琛ㄧ潃鈥滅畻娉曗€濊繖涓瘝鑲畾鏄湪绗簩椤点€佺鍗佷笁椤点€佺鍥涘崄浜岄〉銆佺浜斿崄鍏〉鍑虹幇杩囥€傝繖绉嶆牴鎹煇涓瘝(涓嶅畬鏁寸殑鏉′欢)鍐嶆煡鎵惧搴旇褰曪紝鍙仛鍊掓帓绱㈠紩銆?/p>

鍐嶇湅涓嬮潰鐨勫浘锛屽ソ濂戒綋浼氫竴涓嬶細
鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/49ac85e92050ae30.jpeg?x-oss-process=style/bb

鍒嗚瘝鍚庣殑鏁版嵁缁撴瀯

鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/e476671247601eb8.jpeg?x-oss-process=style/bb

鎴戜滑杈撳叆涓€娈垫枃瀛楋紝Elasticsearch浼氭牴鎹垎璇嶅櫒瀵规垜浠殑閭f鏂囧瓧杩涜鍒嗚瘝锛堜篃灏辨槸鍥句笂鎵€鐪嬪埌鐨凙da/Allen/Sara..)锛岃繖浜涘垎璇嶆眹鎬昏捣鏉ユ垜浠彨鍋歍erm Dictionary锛岃€屾垜浠渶瑕侀€氳繃鍒嗚瘝鎵惧埌瀵瑰簲鐨勮褰曪紝杩欎簺鏂囨。ID淇濆瓨鍦≒ostingList

鍦═erm Dictionary涓殑璇嶇敱浜庢槸闈炲父闈炲父澶氱殑锛屾墍浠ユ垜浠細涓哄叾杩涜鎺掑簭锛岀瓑瑕佹煡鎵剧殑鏃跺€欏氨鍙互閫氳繃浜屽垎鏉ユ煡锛屼笉闇€瑕侀亶鍘嗘暣涓猅erm Dictionary

鐢变簬Term Dictionary鐨勮瘝瀹炲湪澶浜嗭紝涓嶅彲鑳芥妸Term Dictionary鎵€鏈夌殑璇嶉兘鏀惧湪鍐呭瓨涓紝浜庢槸Elasticsearch杩樻娊浜嗕竴灞傚彨鍋歍erm Index锛岃繖灞傚彧瀛樺偍 閮ㄥ垎 璇嶇殑鍓嶇紑锛孴erm Index浼氬瓨鍦ㄥ唴瀛樹腑锛堟绱細鐗瑰埆蹇級

Term Index鍦ㄥ唴瀛樹腑鏄互FST锛團inite State Transducers锛夌殑褰㈠紡淇濆瓨鐨勶紝鍏剁壒鐐规槸闈炲父鑺傜渷鍐呭瓨銆侳ST鏈変袱涓紭鐐癸細
1锛夌┖闂村崰鐢ㄥ皬銆傞€氳繃瀵硅瘝鍏镐腑鍗曡瘝鍓嶇紑鍜屽悗缂€鐨勯噸澶嶅埄鐢紝鍘嬬缉浜嗗瓨鍌ㄧ┖闂达紱
2锛夋煡璇㈤€熷害蹇€侽(len(str))鐨勬煡璇㈡椂闂村鏉傚害銆?/p>

鍓嶉潰璁插埌浜員erm Index鏄瓨鍌ㄥ湪鍐呭瓨涓殑锛屼笖Elasticsearch鐢‵ST锛團inite State Transducers锛夌殑褰㈠紡淇濆瓨锛堣妭鐪佸唴瀛樼┖闂达級銆俆erm Dictionary鍦‥lasticsearch涔熸槸涓轰粬杩涜鎺掑簭锛堟煡鎵剧殑鏃跺€欐柟渚匡級锛屽叾瀹濸ostingList涔熸湁瀵瑰簲鐨勪紭鍖栥€?br /> PostingList浼氫娇鐢‵rame Of Reference锛團OR锛夌紪鐮佹妧鏈閲岃竟鐨勬暟鎹繘琛屽帇缂╋紝鑺傜害纾佺洏绌洪棿銆?br /> 鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/0a79629a90e32902.jpeg?x-oss-process=style/bb

PostingList閲岃竟瀛樼殑鏄枃妗D锛屾垜浠煡鐨勬椂鍊欏線寰€闇€瑕佸杩欎簺鏂囨。ID鍋氫氦闆嗗拰骞堕泦鐨勬搷浣滐紙姣斿鍦ㄥ鏉′欢鏌ヨ鏃?锛孭ostingList浣跨敤Roaring Bitmaps鏉ュ鏂囨。ID杩涜浜ゅ苟闆嗘搷浣溿€?/p>

浣跨敤Roaring Bitmaps鐨勫ソ澶勫氨鏄彲浠ヨ妭鐪佺┖闂村拰蹇€熷緱鍑轰氦骞堕泦鐨勭粨鏋溿€?br /> 鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/2f498bfcad6bf161.jpeg?x-oss-process=style/bb

鎵€浠ュ埌杩欓噷鎴戜滑鎬荤粨涓€涓婨lasticsearch鐨勬暟鎹粨鏋勬湁浠€涔堢壒鐐癸細
鎶€鏈浘鐗? src=
https://mmbiz.qpic.cn/sz_mmbiz_jpg/2BGWl1qPxib0bRFtypiaZQYvF8c6jrGaXAStRPlG9EdiafSyJeib83230WTOHk1jj3OojmFaU6ra6elEedLIgmibcWg/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1

Elasticsearch鐨勬湳璇拰鏋舵瀯

鍦ㄨ瑙lasticsearch鐨勬灦鏋勪箣鍓嶏紝棣栧厛鎴戜滑寰椾簡瑙d竴涓婨lasticsearch鐨勪竴浜涘父瑙佹湳璇€?/p>

Index锛欵lasticsearch鐨処ndex鐩稿綋浜庢暟鎹簱鐨凾able

Type锛氳繖涓湪鏂扮殑Elasticsearch鐗堟湰宸茬粡搴熼櫎锛堝湪浠ュ墠鐨凟lasticsearch鐗堟湰锛屼竴涓狪ndex涓嬫敮鎸佸涓猅ype--鏈夌偣绫讳技浜庢秷鎭槦鍒椾竴涓猼opic涓嬪涓猤roup鐨勬蹇碉級

Document锛欴ocument鐩稿綋浜庢暟鎹簱鐨勪竴琛岃褰?/p>

Field锛氱浉褰撲簬鏁版嵁搴撶殑Column鐨勬蹇?/p>

Mapping锛氱浉褰撲簬鏁版嵁搴撶殑Schema鐨勬蹇?/p>

DSL锛氱浉褰撲簬鏁版嵁搴撶殑SQL锛堢粰鎴戜滑璇诲彇Elasticsearch鏁版嵁鐨凙PI锛?/p>

鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/4c87fb1488ae694d.jpeg?x-oss-process=style/bb

鐩镐俊澶у鐪嬪畬涓婇潰鐨勫姣斿浘锛屽Elasticsearch鐨勪竴浜涙湳璇氨涓嶉毦鐞嗚В浜嗐€傞偅Elasticsearch鐨勬灦鏋勬槸鎬庝箞鏍风殑鍛紵涓嬮潰鎴戜滑鏉ョ湅鐪嬶細

涓€涓狤lasticsearch闆嗙兢浼氭湁澶氫釜Elasticsearch鑺傜偣锛屾墍璋撹妭鐐瑰疄闄呬笂灏辨槸杩愯鐫€Elasticsearch杩涚▼鐨勬満鍣ㄣ€?br /> 鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/3c5431e7e272353e.jpeg?x-oss-process=style/bb

鍦ㄤ紬澶氱殑鑺傜偣涓紝鍏朵腑浼氭湁涓€涓狹aster Node锛屽畠涓昏璐熻矗缁存姢绱㈠紩鍏冩暟鎹€佽礋璐e垏鎹富鍒嗙墖鍜屽壇鏈垎鐗囪韩浠界瓑宸ヤ綔锛堝悗闈細璁插埌鍒嗙墖鐨勬蹇碉級锛屽鏋滀富鑺傜偣鎸備簡锛屼細閫変妇鍑轰竴涓柊鐨勪富鑺傜偣銆?br /> 鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/a27f04b40d53acb4.jpeg?x-oss-process=style/bb

浠庝笂闈㈡垜浠篃宸茬粡寰楃煡锛孍lasticsearch鏈€澶栧眰鐨勬槸Index锛堢浉褰撲簬鏁版嵁搴?琛ㄧ殑姒傚康锛夛紱涓€涓狪ndex鐨勬暟鎹垜浠彲浠ュ垎鍙戝埌涓嶅悓鐨凬ode涓婅繘琛屽瓨鍌紝杩欎釜鎿嶄綔灏卞彨鍋氬垎鐗囥€?/p>

姣斿鐜板湪鎴戦泦缇ら噷杈规湁4涓妭鐐癸紝鎴戠幇鍦ㄦ湁涓€涓狪ndex锛屾兂灏嗚繖涓狪ndex鍦?涓妭鐐逛笂瀛樺偍锛岄偅鎴戜滑鍙互璁剧疆涓?涓垎鐗囥€傝繖4涓垎鐗囩殑鏁版嵁鍚堣捣鏉ュ氨鏄疘ndex鐨勬暟鎹?br /> 鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/a7d730c3413c4d97.jpeg?x-oss-process=style/bb

涓轰粈涔堣鍒嗙墖锛熷師鍥犱篃寰堢畝鍗曪細
濡傛灉涓€涓狪ndex鐨勬暟鎹噺澶ぇ锛屽彧鏈変竴涓垎鐗囷紝閭e彧浼氬湪涓€涓妭鐐逛笂瀛樺偍锛岄殢鐫€鏁版嵁閲忕殑澧為暱锛屼竴涓妭鐐规湭蹇呰兘鎶婁竴涓狪ndex瀛樺偍涓嬫潵銆?br /> 澶氫釜鍒嗙墖锛屽湪鍐欏叆鎴栨煡璇㈢殑鏃跺€欏氨鍙互骞惰鎿嶄綔锛堜粠鍚勪釜鑺傜偣涓鍐欐暟鎹紝鎻愰珮鍚炲悙閲忥級

鐜板湪闂鏉ヤ簡锛屽鏋滄煇涓妭鐐规寕浜嗭紝閭i儴鍒嗘暟鎹氨涓簡鍚楋紵鏄剧劧Elasticsearch涔熶細鎯冲埌杩欎釜闂锛屾墍浠ュ垎鐗囦細鏈変富鍒嗙墖鍜屽壇鏈垎鐗囦箣鍒嗭紙涓轰簡瀹炵幇楂樺彲鐢級

鏁版嵁鍐欏叆鐨勬椂鍊欐槸鍐欏埌涓诲垎鐗囷紝鍓湰鍒嗙墖浼氬鍒朵富鍒嗙墖鐨勬暟鎹紝璇诲彇鐨勬椂鍊欎富鍒嗙墖鍜屽壇鏈垎鐗囬兘鍙互璇汇€?/p>

Index闇€瑕佸垎涓哄灏戜釜涓诲垎鐗囧拰鍓湰鍒嗙墖閮芥槸鍙互閫氳繃閰嶇疆璁剧疆鐨?br /> 鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/f2d0ec61b5e4b7c3.jpeg?x-oss-process=style/bb

濡傛灉鏌愪釜鑺傜偣鎸備簡锛屽墠闈㈡墍鎻愰珮鐨凪aster Node灏变細鎶婂搴旂殑鍓湰鍒嗙墖鎻愭嫈涓轰富鍒嗙墖锛岃繖鏍峰嵆渚胯妭鐐规寕浜嗭紝鏁版嵁灏变笉浼氫涪銆?/p>

鍒拌繖閲屾垜浠彲浠ョ畝鍗曟€荤粨涓€涓婨lasticsearch鐨勬灦鏋勪簡锛?br /> 鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/aea5ad333db601f0.jpeg?x-oss-process=style/bb


http://img.blog.itpub.net/blog/2020/01/15/ec4b71bc1213e12b.jpeg?x-oss-process=style/bb

闆嗙兢涓婄殑姣忎釜鑺傜偣閮芥槸coordinating node锛堝崗璋冭妭鐐癸級锛屽崗璋冭妭鐐硅〃鏄庤繖涓妭鐐瑰彲浠ュ仛璺敱銆傛瘮濡傝妭鐐?鎺ユ敹鍒颁簡璇锋眰锛屼絾鍙戠幇杩欎釜璇锋眰鐨勬暟鎹簲璇ユ槸鐢辫妭鐐?澶勭悊锛堝洜涓轰富鍒嗙墖鍦ㄨ妭鐐?涓婏級锛屾墍浠ヤ細鎶婅姹傝浆鍙戝埌鑺傜偣2涓娿€?/p>

coodinate锛堝崗璋冿級鑺傜偣閫氳繃hash绠楁硶鍙互璁$畻鍑烘槸鍦ㄥ摢涓富鍒嗙墖涓婏紝鐒跺悗璺敱鍒板搴旂殑鑺傜偣
shard = hash(document_id) % (num_of_primary_shards)

璺敱鍒板搴旂殑鑺傜偣浠ュ強瀵瑰簲鐨勪富鍒嗙墖鏃讹紝浼氬仛浠ヤ笅鐨勪簨锛?br /> 1銆佸皢鏁版嵁鍐欏埌鍐呭瓨缂撳瓨鍖?br /> 2銆佺劧鍚庡皢鏁版嵁鍐欏埌translog缂撳瓨鍖?br /> 3銆佹瘡闅?s鏁版嵁浠巄uffer涓璻efresh鍒癋ileSystemCache涓紝鐢熸垚segment鏂囦欢锛屼竴鏃︾敓鎴恠egment鏂囦欢锛屽氨鑳介€氳繃绱㈠紩鏌ヨ鍒颁簡
4銆乺efresh瀹岋紝memory buffer灏辨竻绌轰簡銆?br /> 5銆佹瘡闅?s涓紝translog 浠巄uffer flush鍒扮鐩樹腑
6銆佸畾鏈?瀹氶噺浠嶧ileSystemCache涓?缁撳悎translog鍐呭flush index鍒扮鐩樹腑銆?/p>

鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/25213cbe268544ed.jpeg?x-oss-process=style/bb

瑙i噴涓€涓嬶細
1銆丒lasticsearch浼氭妸鏁版嵁鍏堝啓鍏ュ唴瀛樼紦鍐插尯锛岀劧鍚庢瘡闅?s鍒锋柊鍒版枃浠剁郴缁熺紦瀛樺尯锛堝綋鏁版嵁琚埛鏂板埌鏂囦欢绯荤粺缂撳啿鍖轰互鍚庯紝鏁版嵁鎵嶅彲浠ヨ妫€绱㈠埌锛夈€傛墍浠ワ細Elasticsearch鍐欏叆鐨勬暟鎹渶瑕?s鎵嶈兘鏌ヨ鍒?br /> 2銆佷负浜嗛槻姝㈣妭鐐瑰畷鏈猴紝鍐呭瓨涓殑鏁版嵁涓㈠け锛孍lasticsearch浼氬彟鍐欎竴浠芥暟鎹埌鏃ュ織鏂囦欢涓婏紝浣嗘渶寮€濮嬬殑杩樻槸鍐欏埌鍐呭瓨缂撳啿鍖猴紝姣忛殧5s鎵嶄細灏嗙紦鍐插尯鐨勫埛鍒扮鐩樹腑銆傛墍浠ワ細Elasticsearch鏌愪釜鑺傜偣濡傛灉鎸備簡锛屽彲鑳戒細閫犳垚鏈?s鐨勬暟鎹涪澶便€?br /> 3銆佺瓑鍒扮鐩樹笂鐨則ranslog鏂囦欢澶у埌涓€瀹氱▼搴︽垨鑰呰秴杩囦簡30鍒嗛挓锛屼細瑙﹀彂commit鎿嶄綔锛屽皢鍐呭瓨涓殑segement鏂囦欢寮傛鍒峰埌纾佺洏涓紝瀹屾垚鎸佷箙鍖栨搷浣溿€?/p>

璇寸櫧浜嗗氨鏄細鍐欏唴瀛樼紦鍐插尯锛堝畾鏃跺幓鐢熸垚segement锛岀敓鎴恡ranslog锛夛紝鑳藉璁╂暟鎹兘琚储寮曘€佽鎸佷箙鍖栥€傛渶鍚庨€氳繃commit瀹屾垚涓€娆$殑鎸佷箙鍖栥€?br /> 鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/ba437a2f703752ad.jpeg?x-oss-process=style/bb

绛変富鍒嗙墖鍐欏畬浜嗕互鍚庯紝浼氬皢鏁版嵁骞惰鍙戦€佸埌鍓湰闆嗚妭鐐逛笂锛岀瓑鍒版墍鏈夌殑鑺傜偣鍐欏叆鎴愬姛灏辫繑鍥瀉ck缁欏崗璋冭妭鐐癸紝鍗忚皟鑺傜偣杩斿洖ack缁欏鎴风锛屽畬鎴愪竴娆$殑鍐欏叆銆?/p>


http://img.blog.itpub.net/blog/2020/01/15/1e88128d2422b165.jpeg?x-oss-process=style/bb

Elasticsearch鏌ヨ

鏌ヨ鎴戜滑鏈€绠€鍗曠殑鏂瑰紡鍙互鍒嗕负涓ょ锛?br /> 1銆佹牴鎹甀D鏌ヨdoc
2銆佹牴鎹畄uery锛堟悳绱㈣瘝锛夊幓鏌ヨ鍖归厤鐨刣oc

public TopDocs search(Query query, int n);
public Document doc(int docID);

鏍规嵁ID鍘绘煡璇㈠叿浣撶殑doc鐨勬祦绋嬫槸锛?br /> 1銆佹绱㈠唴瀛樼殑Translog鏂囦欢
2銆佹绱㈢‖鐩樼殑Translog鏂囦欢
3銆佹绱㈢‖鐩樼殑Segement鏂囦欢

鏍规嵁query鍘诲尮閰峝oc鐨勬祦绋嬫槸锛?br /> 鍚屾椂鍘绘煡璇㈠唴瀛樺拰纭洏鐨凷egement鏂囦欢
鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/e28927442f4c96ed.jpeg?x-oss-process=style/bb

浠庝笂闈㈡墍璁茬殑鍐欏叆娴佺▼锛屾垜浠氨鍙互鐭ラ亾锛屽洜涓簊egement鏂囦欢鏄瘡闅斾竴绉掓墠鐢熸垚涓€娆$殑锛孏et锛堥€氳繃ID鍘绘煡Doc鏄疄鏃剁殑锛夛紝Query锛堥€氳繃query鍘诲尮閰岲oc鏄繎瀹炴椂鐨勶級

Elasticsearch鏌ヨ鍙堝垎鍙互涓轰笁涓樁娈碉細
1銆丵UERY_AND_FETCH锛堟煡璇㈠畬灏辫繑鍥炴暣涓狣oc鍐呭锛?br /> 2銆丵UERY_THEN_FETCH锛堝厛鏌ヨ鍑哄搴旂殑Doc id 锛岀劧鍚庡啀鏍规嵁Doc id 鍖归厤鍘诲搴旂殑鏂囨。锛?br /> 3銆丏FS_QUERY_THEN_FETCH锛堝厛绠楀垎锛屽啀鏌ヨ锛?/p>

銆岃繖閲岀殑鍒嗘寚鐨勬槸 璇嶉鐜囧拰鏂囨。鐨勯鐜囷紙Term Frequency銆丏ocument Frequency锛変紬鎵€鍛ㄧ煡锛屽嚭鐜伴鐜囪秺楂橈紝鐩稿叧鎬у氨鏇村己銆?br /> 鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/695a11190bcea92c.jpeg?x-oss-process=style/bb

涓€鑸垜浠敤寰楁渶澶氱殑灏辨槸QUERY_THEN_FETCH锛岀涓€绉嶆煡璇㈠畬灏辫繑鍥炴暣涓狣oc鍐呭锛圦UERY_AND_FETCH锛夊彧閫傚悎浜庡彧闇€瑕佹煡涓€涓垎鐗囩殑璇锋眰銆?/p>

QUERY_THEN_FETCH鎬讳綋鐨勬祦绋嬫祦绋嬪ぇ姒傛槸锛?br /> 1銆佸鎴风璇锋眰鍙戦€佸埌闆嗙兢鐨勬煇涓妭鐐逛笂銆傞泦缇や笂鐨勬瘡涓妭鐐归兘鏄痗oordinate node锛堝崗璋冭妭鐐癸級
2銆佺劧鍚庡崗璋冭妭鐐瑰皢鎼滅储鐨勮姹傝浆鍙戝埌鎵€鏈夊垎鐗囦笂锛堜富鍒嗙墖鍜屽壇鏈垎鐗囬兘琛岋級
3銆佹瘡涓垎鐗囧皢鑷繁鎼滅储鍑虹殑缁撴灉(doc id)杩斿洖缁欏崗璋冭妭鐐癸紝鐢卞崗璋冭妭鐐硅繘琛屾暟鎹殑鍚堝苟銆佹帓搴忋€佸垎椤电瓑鎿嶄綔锛屼骇鍑烘渶缁堢粨鏋溿€?br /> 4銆佹帴鐫€鐢卞崗璋冭妭鐐规牴鎹?doc id 鍘诲悇涓妭鐐逛笂鎷夊彇瀹為檯鐨?document 鏁版嵁锛屾渶缁堣繑鍥炵粰瀹㈡埛绔€?/p>

Query Phase闃舵鏃惰妭鐐瑰仛鐨勪簨锛?br /> 1銆佸崗璋冭妭鐐瑰悜鐩爣鍒嗙墖鍙戦€佹煡璇㈢殑鍛戒护锛堣浆鍙戣姹傚埌涓诲垎鐗囨垨鑰呭壇鏈垎鐗囦笂锛?br /> 2銆佹暟鎹妭鐐癸紙鍦ㄦ瘡涓垎鐗囧唴鍋氳繃婊ゃ€佹帓搴忕瓑绛夋搷浣滐級锛岃繑鍥瀌oc id缁欏崗璋冭妭鐐?/p>

Fetch Phase闃舵鏃惰妭鐐瑰仛鐨勬槸锛?br /> 1銆佸崗璋冭妭鐐瑰緱鍒版暟鎹妭鐐硅繑鍥炵殑doc id锛屽杩欎簺doc id鍋氳仛鍚堬紝鐒跺悗灏嗙洰鏍囨暟鎹垎鐗囧彂閫佹姄鍙栧懡浠わ紙甯屾湜鎷垮埌鏁翠釜Doc璁板綍锛?br /> 2銆佹暟鎹妭鐐规寜鍗忚皟鑺傜偣鍙戦€佺殑doc id锛屾媺鍙栧疄闄呴渶瑕佺殑鏁版嵁杩斿洖缁欏崗璋冭妭鐐?/p>

涓绘祦绋嬫垜鐩镐俊澶у涔熶笉浼氬お闅剧悊瑙o紝璇寸櫧浜嗗氨鏄細鐢变簬Elasticsearch鏄垎甯冨紡鐨勶紝鎵€浠ラ渶瑕佷粠鍚勪釜鑺傜偣閮芥媺鍙栧搴旂殑鏁版嵁锛岀劧鍚庢渶缁堢粺涓€鍚堟垚缁欏鎴风

鍙槸Elasticsearch鎶婅繖浜涙椿閮藉共浜嗭紝鎴戜滑鍦ㄤ娇鐢ㄧ殑鏃跺€欐棤鎰熺煡鑰屽凡銆?br /> 鎶€鏈浘鐗? src=
http://img.blog.itpub.net/blog/2020/01/15/1fd511e83098d3be.jpeg?x-oss-process=style/bb

鏈€鍚?br /> 杩欑瘒鏂囩珷涓昏瀵笶lasticsearch绠€鍗曞叆浜嗕釜闂紝瀹為檯浣跨敤鑲畾杩樹細閬囧埌寰堝鍧戯紝浣嗘垜鐩墠灏卞埌杩欓噷灏辩粨鏉熶簡銆?br /> 鎶€鏈浘鐗? src=

杞嚜锛?br /> https://mp.weixin.qq.com/s/tq3zMbs-ZmSK-trprq82gg
http://blog.itpub.net/69900354/viewspace-2673541/

以上是关于銆屾壂鐩层€?Elasticsearch的主要内容,如果未能解决你的问题,请参考以下文章

ElasticSearch学习问题记录——Invalid shift value in prefixCoded bytes (is encoded value really an INT?)(代码片段

濡備綍浣跨敤Nmap杩涜绔彛鎵弿锛堜簲锛夊浣曡繘琛屾壂鎻忔妧鏈殑閫夋嫨

銆屾櫄娴嬪弽鎬濄€?020-11-27 寤鸿

銆屾煡缂鸿ˉ婕忋€嶅珐鍥轰綘鐨凥TTP鐭ヨ瘑浣撶郴

Elasticsearch笔记九之优化

姣忔棩涓€鍙ヤ辅銆屾槬鏅氥€嶇殑鑻辨枃鏄?spring festival party 鍚楋紵涓嶅锛佸氨宸竴涓瘝锛?/h1>