Python鎿嶄綔es

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python鎿嶄綔es相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/required' title='required'>required   jni   缂撳瓨   form   灏变細   html   verify   澶氬皯   top   

鎿嶄綔鍑犱釜鏂归潰

  • 缁撴灉杩囨护锛屽浜庤繑鍥炵粨鏋滃仛杩囨护锛屼富瑕佹槸浼樺寲杩斿洖鍐呭銆?/strong>
  • 鐩存帴鎿嶄綔elasticsearch瀵硅薄锛屽鐞嗕竴浜涚畝鍗曠殑绱㈠紩淇℃伅銆備竴涓嬪嚑涓柟闈㈤兘鏄缓绔嬪湪es瀵硅薄鐨勫熀纭€涓娿€?/strong>
  • Indices锛屽叧浜庣储寮曠殑缁嗚妭鎿嶄綔锛屾瘮濡傚垱寤鸿嚜瀹氫箟鐨刴appings銆?/strong>
  • Cluster锛屽叧浜庨泦缇ょ殑鐩稿叧鎿嶄綔銆?/strong>
  • Nodes锛屽叧浜庤妭鐐圭殑鐩稿叧鎿嶄綔銆?/strong>
  • Cat API锛屾崲涓€绉嶆煡璇㈡柟寮忥紝涓€鑸殑杩斿洖閮芥槸json绫诲瀷鐨勶紝cat鎻愪緵浜嗙畝娲佺殑杩斿洖缁撴灉銆?/strong>
  • Snapshot锛屽揩鐓х浉鍏筹紝蹇収鏄粠姝e湪杩愯鐨凟lasticsearch闆嗙兢涓幏鍙栫殑澶囦唤銆傛垜浠彲浠ユ媿鎽勫崟涓储寮曟垨鏁翠釜缇ら泦鐨勫揩鐓э紝骞跺皢鍏跺瓨鍌ㄥ湪鍏变韩鏂囦欢绯荤粺鐨勫瓨鍌ㄥ簱涓紝骞朵笖鏈変竴浜涙彃浠舵敮鎸丼3锛孒DFS锛孉zure锛孏oogle浜戝瓨鍌ㄧ瓑涓婄殑杩滅▼瀛樺偍搴撱€?/li>
  • Task Management API锛屼换鍔$鐞咥PI鏄柊鐨勶紝浠嶅簲琚涓烘祴璇曠増鍔熻兘銆侫PI鍙兘浠ヤ笉鍚戝悗鍏煎鐨勬柟寮忔洿鏀广€?/li>

缁撴灉杩囨护

  • filter_path鍙傛暟鐢ㄤ簬杩囨护鍑忓皯es杩斿洖淇℃伅锛屽彲浠ユ寚瀹氳繑鍥炵浉鍏崇殑鍐呭锛岃繕鏀寔涓€浜涢€氶厤绗︾殑鎿嶄綔*
 1 body = 
 2     "query": 
 3         "match": 
 4             "name": "鎴愰兘"
 5         
 6     
 7 
 8 # print(es.search(index="p1", body=body))
 9 print(es.search(index="p1", body=body, filter_path=["hits.hits"]))
10 print(es.search(index="p1", body=body, filter_path=["hits.hits._source"]))
11 print(es.search(index="p1", body=body, filter_path=["hits.hits._source", "hits.total"]))
12 print(es.search(index="p1", body=body, filter_path=["hits.*"]))
13 print(es.search(index="p1", body=body, filter_path=["hits.hits._*"]))

Elasticsearch(es瀵硅薄 )

  • es.index 鍚戞寚瀹氱储寮曟坊鍔犳洿鏂版枃妗?濡傛灉绱㈠紩涓嶅瓨鍦ㄥ氨浼氬垱寤猴紝鐒跺悗鎵ц娣诲姞鏇存柊绛夋搷浣?/strong>
1 # print(es.index(index="p2", doc_type="doc", id=1, body="name": "妫掓", "age": "18"))  # 姝e父
2 # print(es.index(index="p2", doc_type="doc", id=2, body="name": "妫掓鍝?, "age": 20))  # 姝e父
3 # print(es.index(index="p2", doc_type="doc", body="name": "鐔婂ぇ", "age": "10"))  # 濡傛灉娣诲姞鏂囨。涓嶅甫id鑷姩浼氬垱寤轰竴涓?/span>
  • es.get 鏌ヨ绱㈠紩涓寚瀹氭枃妗?/span>
1 # get(self, index, id, doc_type="_doc", params=None):
2 # print(es.get(index=鈥榩2鈥? doc_type=鈥榙oc鈥? id=1))  # 姝e父
3 # print(es.get(index=鈥榩2鈥? doc_type=鈥榙oc鈥?)  # TypeError: get() missing 1 required positional argument: 鈥榠d鈥?鍙兘鍙栧崟涓枃妗e璞?/span>
4 # print(es.get(index=鈥榩2鈥? id=2))  # 瑕佹寚瀹氭枃妗g被鍨媏lasticsearch.exceptions.NotFoundError: NotFoundError(404, 鈥榹"_index":"p2","_type":"_doc","_id":"2","found":false鈥?
  • es.search 鎵ц鎼滅储鏌ヨ骞惰幏鍙栧叾鍖归厤瀹冨彲浠ヨ窡澶嶆潅鐨勬煡璇㈡潯浠?/strong> 
  1. index瑕佹悳绱㈢殑浠ラ€楀彿鍒嗛殧鐨勭储寮曞悕绉板垪琛? 浣跨敤_all 鎴栫┖瀛楃涓插鎵€鏈夌储寮曟墽琛屾搷浣溿€?/strong>
  2. doc_type 瑕佹悳绱㈢殑浠ラ€楀彿鍒嗛殧鐨勬枃妗g被鍨嬪垪琛? 鐣欑┖浠ュ鎵€鏈夌被鍨嬫墽琛屾搷浣溿€?/strong>
  3. body 浣跨敤Query DSL锛圦ueryDomain Specific Language鏌ヨ琛ㄨ揪寮忥級鐨勬悳绱㈠畾涔夈€?/strong>
  4. _source 杩斿洖_source瀛楁鐨則rue鎴杅alse锛屾垨杩斿洖鐨勫瓧娈靛垪琛紝杩斿洖鎸囧畾瀛楁銆?/strong>
  5. _source_exclude瑕佷粠杩斿洖鐨?code>_source瀛楁涓帓闄ょ殑瀛楁鍒楄〃锛岃繑鍥炵殑鎵€鏈夊瓧娈典腑锛屾帓闄ゅ摢浜涘瓧娈点€?/strong>
  6. _source_include浠?code>_source瀛楁涓彁鍙栧拰杩斿洖鐨勫瓧娈靛垪琛紝璺?code>_source宸笉澶?/strong>銆?/li>
1 # print(es.search(index=鈥榩2鈥? body="query": "match": "age": "10"))
2 # print(es.search(index=鈥榩2鈥? body="query": "match": "age": "10", _source=[鈥榥ame鈥? 鈥榓ge鈥榏))
3 # print(es.search(index=鈥榩2鈥? body="query": "match": "age": "10", _source_exclude=[鈥榓ge鈥榏))
4 print(es.search(index=鈥?/span>p2鈥?/span>, body="query": "match": "age": "10", _source_include=[鈥?/span>age鈥?/span>]))

 鎺掗櫎缁撴灉

鈥榯ook鈥? 3, 鈥榯imed_out鈥? False, 鈥榑shards鈥? 鈥榯otal鈥? 5, 鈥榮uccessful鈥? 5, 鈥榮kipped鈥? 0, 鈥榝ailed鈥? 0, 鈥榟its鈥? 鈥榯otal鈥? 2, 鈥榤ax_score鈥? 0.2876821, 鈥榟its鈥? [鈥榑index鈥? 鈥榩2鈥? 鈥榑type鈥? 鈥榙oc鈥? 鈥榑id鈥? 鈥榣EP_u2wBsrL_vQjNIMFf鈥? 鈥榑score鈥? 0.2876821, 鈥榑source鈥? 鈥榥ame鈥? 鈥樼唺澶р€榼, 鈥榑index鈥? 鈥榩2鈥? 鈥榑type鈥? 鈥榙oc鈥? 鈥榑id鈥? 鈥榃0MjvGwBsrL_vQjNNd0x鈥? 鈥榑score鈥? 0.2876821, 鈥榑source鈥? 鈥榮ex鈥? 鈥樼敺鈥? 鈥榥ame鈥? 鈥樼唺澶р€? 鈥榙esc鈥? 鈥樺崱閫氭櫤闅滃効绔モ€榼]
  • es.get_source锛岄€氳繃绱㈠紩銆佺被鍨嬪拰ID鑾峰彇鏂囨。鐨勬潵婧愶紝鍏跺疄锛岀洿鎺ヨ繑鍥炴兂瑕佺殑瀛楀吀銆?/strong> 
1 print(es.get_source(index=鈥?/span>p2鈥?/span>, doc_type=鈥?/span>doc鈥?/span>, id=鈥?/span>1鈥?/span>))
  • es.count锛屾墽琛屾煡璇㈠苟鑾峰彇璇ユ煡璇㈢殑鍖归厤鏁般€傛瘮濡傛煡璇㈠勾榫勬槸18鐨勬枃妗c€?/strong>
 1 body = 
 2     "query": 
 3         "match": 
 4             "age": 18
 5         
 6     
 7 
 8 # print(es.count(index=鈥榩2鈥? doc_type=鈥榙oc鈥? body=body))
 9 # print(es.count(index=鈥榩2鈥? doc_type=鈥榙oc鈥? body=body)[鈥榗ount鈥榏)
10 print(es.count(index=鈥?/span>p2鈥?/span>)) # 鏌ュ湪p2绱㈠紩涓€荤殑鏂囨。涓暟鈥榗ount鈥? 4, 鈥榑shards鈥? 鈥榯otal鈥? 5, 鈥榮uccessful鈥? 5, 鈥榮kipped鈥? 0, 鈥榝ailed鈥? 0
11 print(es.count(index=鈥?/span>p2鈥?/span>, doc_type=鈥?/span>doc鈥?/span>)) # 鈥榗ount鈥? 4, 鈥榑shards鈥? 鈥榯otal鈥? 5, 鈥榮uccessful鈥? 5, 鈥榮kipped鈥? 0, 鈥榝ailed鈥? 0
  • es.create锛屽垱寤虹储寮曪紙绱㈠紩涓嶅瓨鍦ㄧ殑璇濓級骞舵柊澧炰竴鏉℃暟鎹紝绱㈠紩瀛樺湪浠呮柊澧烇紙鍙兘鏂板锛岄噸澶嶆墽琛屼細鎶ラ敊锛夛紝杩樻槸瑙夊緱index濂界敤浜?/strong>
1 # print(es.create(index=鈥榩2鈥? doc_type=鈥榙oc鈥? id=3, body="city": "鎴愰兘", "desc": "鏃呮父鐨勫湴鏂归澶氾紝 灏忓悆鍑哄悕"))
2 print(es.get_source(index=鈥?/span>p2鈥?/span>, doc_type=鈥?/span>doc鈥?/span>, id=3)) 
  • es.delete锛屽垹闄ゆ寚瀹氱殑鏂囨。銆傛瘮濡傚垹闄ゆ枃绔爄d涓?鐨勬枃妗o紝浣嗕笉鑳藉垹闄や粎鍙垹闄ょ储寮曪紝濡傛灉鎯宠鍒犻櫎绱㈠紩锛岃繕闇€瑕乪s.indices.delete鏉ュ鐞?/strong>
  • es.delete_by_query锛屽垹闄や笌鏌ヨ鍖归厤鐨勬墍鏈夋枃妗c€?/strong>
1 # print(es.delete(index=鈥榩2鈥? doc_type=鈥榙oc鈥? id=1))
2 # print(es.delete_by_query(index=鈥榩2鈥? body="query": "match": "age": 20))
3 # print(es.search(index=鈥榩2鈥?)
  • es.exists锛屾煡璇lasticsearch涓槸鍚﹀瓨鍦ㄦ寚瀹氱殑鏂囨。锛岃繑鍥炰竴涓竷灏斿€笺€?/li>
1 print(es.exists(index=鈥?/span>p2鈥?/span>, doc_type=鈥?/span>doc鈥?/span>, id=鈥?/span>1鈥?/span>))
  • es.info锛岃幏鍙栧綋鍓嶉泦缇ょ殑鍩烘湰淇℃伅銆?/li>
1 print(es.info())
  • es.ping锛屽鏋滈泦缇ゅ凡鍚姩锛屽垯杩斿洖True锛屽惁鍒欒繑鍥濬alse銆?/li>
1 print(es.ping())

Indices(es.indices 绱㈠紩鐩稿叧)銆€銆€

 鍒涘缓绱㈠紩 

 1 body = 
 2     "mappings": 
 3         "doc": 
 4             "dynamic": "strict",
 5             "properties": 
 6                 "title": 
 7                     "type": "text",
 8                     "analyzer": "ik_max_word"
 9                 ,
10                 "url": 
11                     "type": "text"
12                 ,
13                 "action_type": 
14                     "type": "text"
15                 ,
16                 "content": 
17                     "type": "text"
18                 
19             
20         
21     
22 
23 
24 print(es.indices.create(index=鈥?/span>p3鈥?/span>, body=body))

鍒涘缓缁撴灉

1 鈥?/span>acknowledged鈥?/span>: True, 鈥?/span>shards_acknowledged鈥?/span>: True, 鈥?/span>index鈥?/span>: 鈥?/span>p3鈥?/span>
  • es.indices.analyze锛岃繑鍥炲垎璇嶇粨鏋溿€?/strong>
1 print(es.indices.analyze(body=鈥?/span>analyzer鈥?/span>: 鈥?/span>ik_max_word鈥?/span>, 鈥?/span>text鈥?/span>: "鐨壒鍜岃尡涓藉綋閫?ldquo;骞村害妯¤寖鎯呬荆”Brad Pitt and Angelina Jolie"))
  • es.indices.delete锛屽湪Elasticsearch涓垹闄ょ储寮曘€?/strong>
1 print(es.indices.delete(index=鈥?/span>p3鈥?/span>))
2 print(es.indices.delete(index=鈥?/span>p2鈥?/span>))    # 鈥榓cknowledged鈥? True
  •  es.indices.put_alias锛屼负涓€涓垨澶氫釜绱㈠紩鍒涘缓鍒悕锛屾煡璇㈠涓储寮曠殑鏃跺€欙紝鍙互浣跨敤杩欎釜鍒悕銆?/strong>
1 print(es.indices.put_alias(index=鈥?/span>p3鈥?/span>, name=鈥?/span>p3_alias鈥?/span>))  # 涓哄崟涓储寮曞垱寤哄埆鍚?/span>
2 print(es.indices.put_alias(index=[鈥?/span>p3鈥?/span>, 鈥?/span>p2鈥?/span>], name=鈥?/span>p23_alias鈥?/span>))  # 涓哄涓储寮曞垱寤哄悓涓€涓埆鍚嶏紝鑱旀煡鐢?/span>
  • es.indices.delete_alias锛屽垹闄や竴涓垨澶氫釜鍒悕銆?/strong>
1 print(es.indices.delete_alias(index=鈥?/span>p1鈥?/span>))
2 print(es.indices.delete_alias(index=[鈥?/span>p1, p2鈥?/span>])) 
  • es.indices.get_mapping锛屾绱㈢储寮曟垨绱㈠紩/绫诲瀷鐨勬槧灏勫畾涔夈€?/strong>
1 print(es.indices.get_mapping(index=鈥?/span>p3鈥?/span>))
  • es.indices.get_settings锛屾绱竴涓垨澶氫釜锛堟垨鎵€鏈夛級绱㈠紩鐨勮缃€?/strong>
1 print(es.indices.get_settings(index=鈥?/span>p3鈥?/span>))
  • es.indices.get锛屽厑璁告绱㈡湁鍏充竴涓垨澶氫釜绱㈠紩鐨勪俊鎭€?/strong>
1 print(es.indices.get(index=鈥?/span>p2鈥?/span>))    # 鏌ヨ鎸囧畾绱㈠紩鏄惁瀛樺湪
2 print(es.indices.get(index=[鈥?/span>p2鈥?/span>, 鈥?/span>p3鈥?/span>]))
  • es.indices.get_alias锛屾绱竴涓垨澶氫釜鍒悕銆?/strong>
1 print(es.indices.get_alias(index=鈥?/span>p2鈥?/span>))
2 print(es.indices.get_alias(index=[鈥?/span>p2鈥?/span>, 鈥?/span>p3鈥?/span>]))
  • es.indices.get_field_mapping锛屾绱㈢壒瀹氬瓧娈电殑鏄犲皠淇℃伅銆?/li>
1 print(es.indices.get_field_mapping(fields=鈥?/span>url鈥?/span>, index=鈥?/span>p3鈥?/span>, doc_type=鈥?/span>doc鈥?/span>))
2 print(es.indices.get_field_mapping(fields=[鈥?/span>url鈥?/span>, 鈥?/span>title鈥?/span>], index=鈥?/span>p3鈥?/span>, doc_type=鈥?/span>doc鈥?/span>))
  • es.indices.delete_alias锛屽垹闄ょ壒瀹氬埆鍚嶃€?/li>
  • es.indices.exists锛岃繑鍥炰竴涓竷灏斿€硷紝鎸囩ず缁欏畾鐨勭储寮曟槸鍚﹀瓨鍦ㄣ€?/li>
  • es.indices.exists_type锛屾鏌ョ储寮?绱㈠紩涓槸鍚﹀瓨鍦ㄧ被鍨?绫诲瀷銆?/li>
  • es.indices.flus锛屾槑纭殑鍒锋柊涓€涓垨澶氫釜绱㈠紩銆?/li>
  • es.indices.get_field_mapping锛屾绱㈢壒瀹氬瓧娈电殑鏄犲皠銆?/li>
  • es.indices.get_template锛屾寜鍚嶇О妫€绱㈢储寮曟ā鏉裤€?/li>
  • es.indices.open锛屾墦寮€涓€涓皝闂殑绱㈠紩浠ヤ娇鍏跺彲鐢ㄤ簬鎼滅储銆?/li>
  • es.indices.close锛屽叧闂储寮曚互浠庣兢闆嗕腑鍒犻櫎瀹冪殑寮€閿€銆傚皝闂储寮曡闃绘杩涜璇?鍐欐搷浣溿€?/li>
  • es.indices.clear_cache锛屾竻闄や笌涓€涓垨澶氫釜绱㈠紩鍏宠仈鐨勬墍鏈夌紦瀛樻垨鐗瑰畾缂撳瓨銆?/li>
  • es.indices.put_alias锛屼负鐗瑰畾绱㈠紩/绱㈠紩鍒涘缓鍒悕銆?/li>
  • es.indices.get_uprade锛岀洃鎺т竴涓垨澶氫釜绱㈠紩鐨勫崌绾х▼搴︺€?/li>
  • es.indices.put_mapping锛屾敞鍐岀壒瀹氱被鍨嬬殑鐗瑰畾鏄犲皠瀹氫箟銆?/li>
  • es.indices.put_settings锛屽疄鏃舵洿鏀圭壒瀹氱储寮曠骇鍒缃€?/li>
  • es.indices.put_template锛屽垱寤轰竴涓储寮曟ā鏉匡紝璇ユā鏉垮皢鑷姩搴旂敤浜庡垱寤虹殑鏂扮储寮曘€?/li>
  • es.indices.rollove锛屽綋鐜版湁绱㈠紩琚涓哄お澶ф垨澶棫鏃讹紝缈昏浆绱㈠紩API灏嗗埆鍚嶈浆绉诲埌鏂扮储寮曘€侫PI鎺ュ彈鍗曚釜鍒悕鍜屾潯浠跺垪琛ㄣ€傚埆鍚嶅繀椤讳粎鎸囧悜鍗曚釜绱㈠紩銆傚鏋滅储寮曟弧瓒虫寚瀹氭潯浠讹紝鍒欏垱寤烘柊绱㈠紩骞跺垏鎹㈠埆鍚嶄互鎸囧悜鏂板埆鍚嶃€?/li>
  • es.indices.segments锛屾彁渚涙瀯寤篖ucene绱㈠紩锛堝垎鐗囩骇鍒級鐨勪綆绾у埆娈典俊鎭€?/li>

Cluster锛堥泦缇ょ浉鍏筹級

  • es.cluster.get_settigns锛岃幏鍙栭泦缇よ缃€?/li>
1 print(es.cluster.get_settings())
  • es.cluster.health锛岃幏鍙栨湁鍏崇兢闆嗚繍琛岀姸鍐电殑闈炲父绠€鍗曠殑鐘舵€併€?/li>
1 print(es.cluster.health()) 
  • es.cluster.state锛岃幏鍙栨暣涓泦缇ょ殑缁煎悎鐘舵€佷俊鎭€?/li>
1 print(es.cluster.state())
  • es.cluster.state锛岃幏鍙栨暣涓泦缇ょ殑缁煎悎鐘舵€佷俊鎭€?/li>
1 print(es.cluster.stats()) 

 Node锛堣妭鐐圭浉鍏筹級 

  • es.nodes.info锛岃繑鍥為泦缇や腑鑺傜偣鐨勪俊鎭€?/li>
1 print(es.nodes.info())  # 杩斿洖鎵€鑺傜偣
2 print(es.nodes.info(node_id=鈥?/span>node1鈥?/span>))   # 鎸囧畾涓€涓妭鐐?/span>
3 print(es.nodes.info(node_id=[鈥?/span>node1鈥?/span>, 鈥?/span>node2鈥?/span>]))   # 鎸囧畾澶氫釜鑺傜偣鍒楄〃
  • es.nodes.stats锛岃幏鍙栭泦缇や腑鑺傜偣缁熻淇℃伅銆?/li>
1 print(es.nodes.stats())
2 print(es.nodes.stats(node_id=鈥?/span>node1鈥?/span>))
3 print(es.nodes.stats(node_id=[鈥?/span>node1鈥?/span>, 鈥?/span>node2鈥?/span>]))
  • es.nodes.hot_threads锛岃幏鍙栨寚瀹氳妭鐐圭殑绾跨▼淇℃伅銆?/li>
1 print(es.nodes.hot_threads(node_id=鈥?/span>node1鈥?/span>))
2 print(es.nodes.hot_threads(node_id=[鈥?/span>node1鈥?/span>, 鈥?/span>node2鈥?/span>]))
  • es.nodes.usage锛岃幏鍙栭泦缇や腑鑺傜偣鐨勫姛鑳戒娇鐢ㄤ俊鎭€?/li>
1 print(es.nodes.usage())
2 print(es.nodes.usage(node_id=鈥?/span>node1鈥?/span>))
3 print(es.nodes.usage(node_id=[鈥?/span>node1鈥?/span>, 鈥?/span>node2鈥?/span>]))

Cat锛堜竴绉嶆煡璇㈡柟寮忥級

  • es.cat.aliases锛岃繑鍥炲埆鍚嶄俊鎭€?/li>
1 print(es.cat.aliases(name=鈥?/span>p23_alias鈥?/span>))
2 print(es.cat.aliases(name=鈥?/span>p23_alias鈥?/span>, format=鈥?/span>json鈥?/span>)) 
  • es.cat.allocation锛岃繑鍥炲垎鐗囦娇鐢ㄦ儏鍐点€?/li>
1 print(es.cat.allocation())
2 print(es.cat.allocation(node_id=[鈥?/span>node1鈥?/span>]))
3 print(es.cat.allocation(node_id=[鈥?/span>node1鈥?/span>, 鈥?/span>node2鈥?/span>], format=鈥?/span>json鈥?/span>))
  • es.cat.count锛孋ount鎻愪緵瀵规暣涓兢闆嗘垨鍗曚釜绱㈠紩鐨勬枃妗h鏁扮殑蹇€熻闂€?/li>
1 print(es.cat.count())  # 闆嗙兢鍐呯殑鏂囨。鎬绘暟
2 print(es.cat.count(index=鈥?/span>p3鈥?/span>))  # 鎸囧畾绱㈠紩鏂囨。鎬绘暟
3 print(es.cat.count(index=[鈥?/span>p3鈥?/span>, 鈥?/span>p2鈥?/span>], format=鈥?/span>json鈥?/span>))  # 杩斿洖涓や釜绱㈠紩鏂囨。鍜?/span>
  • es.cat.fielddata锛屽熀浜庢瘡涓妭鐐规樉绀烘湁鍏冲綋鍓嶅姞杞界殑fielddata鐨勪俊鎭€傛湁浜涙暟鎹负浜嗘煡璇㈡晥鐜囷紝浼氭斁鍦ㄥ唴瀛樹腑锛宖ielddata鐢ㄦ潵鎺у埗鍝簺鏁版嵁搴旇琚斁鍦ㄥ唴瀛樹腑锛岃€岃繖涓猠s.cat.fielddata鍒欐煡璇㈢幇鍦ㄥ摢浜涙暟鎹湪鍐呭瓨涓紝鏁版嵁澶у皬绛変俊鎭€?/p>

1 print(es.cat.fielddata())
2 print(es.cat.fielddata(format=鈥?/span>json鈥?/span>, bytes=鈥?/span>b鈥?/span>))
1 bytes 鍗曚綅鈥?/span>b鈥?/span>锛?span style="color: #800000;">鈥?/span>k鈥?/span>锛?span style="color: #800000;">鈥?/span>kb鈥?/span>锛?span style="color: #800000;">鈥?/span>m鈥?/span>锛?span style="color: #800000;">鈥?/span>mb鈥?/span>锛?span style="color: #800000;">鈥?/span>g鈥?/span>锛?span style="color: #800000;">鈥?/span>gb鈥?/span>锛?span style="color: #800000;">鈥?/span>t鈥?/span>锛?span style="color: #800000;">鈥?/span>tb鈥?/span> 锛?span style="color: #800000;">鈥?/span>p鈥?/span>锛?span style="color: #800000;">鈥?/span>pb鈥?/span>
  • es.cat.health锛屼粠闆嗙兢涓環ealth閲岄潰杩囨护鍑虹畝娲佺殑闆嗙兢鍋ュ悍淇℃伅
1 print(es.cat.health())
2 print(es.cat.health(format=鈥?/span>json鈥?/span>))
  • es.cat.help锛岃繑鍥瀍s.cat鐨勫府鍔╀俊鎭€?/li>
1 print(es.cat.help())
  • es.cat.indices锛岃繑鍥炵储寮曠殑淇℃伅銆?/li>
1 print(es.cat.indices())
2 print(es.cat.indices(index=鈥?/span>p3鈥?/span>))
3 print(es.cat.indices(index=鈥?/span>p3鈥?/span>, format=鈥?/span>json鈥?/span>))
  • es.cat.master锛岃繑鍥為泦缇や腑涓昏妭鐐圭殑IP锛岀粦瀹欼P鍜岃妭鐐瑰悕绉般€?/li>
1 print(es.cat.master())
2 print(es.cat.master(format=鈥?/span>json鈥?/span>))
  • es.cat.nodeattrs锛岃繑鍥炶妭鐐圭殑鑷畾涔夊睘鎬с€?/li>
1 print(es.cat.nodeattrs())
2 print(es.cat.nodeattrs(format=鈥?/span>json鈥?/span>))
  • es.cat.nodes锛岃繑鍥炶妭鐐圭殑鎷撴墤锛岃繖浜涗俊鎭湪鏌ョ湅鏁翠釜闆嗙兢鏃堕€氬父寰堟湁鐢紝鐗瑰埆鏄ぇ鍨嬮泦缇ゃ€傛垜鏈夊灏戠鍚堟潯浠剁殑鑺傜偣锛?/li>
1 print(es.cat.nodes())
2 print(es.cat.nodes(format=鈥?/span>json鈥?/span>))
  • es.cat.plugins锛岃繑鍥炶妭鐐圭殑鎻掍欢淇℃伅銆?/li>
1 print(es.cat.plugins())
2 print(es.cat.plugins(format=鈥?/span>json鈥?/span>))
  • es.cat.segments锛岃繑鍥炴瘡涓储寮曠殑Lucene鏈夊叧鐨勪俊鎭€?/li>
1 print(es.cat.segments())
2 print(es.cat.segments(index=鈥?/span>p3鈥?/span>))
3 print(es.cat.segments(index=鈥?/span>p3鈥?/span>, format=鈥?/span>json鈥?/span>))
  • es.cat.shards锛岃繑鍥炲摢涓妭鐐瑰寘鍚摢浜涘垎鐗囩殑淇℃伅銆?/li>
1 print(es.cat.shards())
2 print(es.cat.shards(index=鈥?/span>p3鈥?/span>))
3 print(es.cat.shards(index=鈥?/span>p3鈥?/span>, format=鈥?/span>json鈥?/span>))
  • es.cat.thread_pool锛岃幏鍙栨湁鍏崇嚎绋嬫睜鐨勪俊鎭€?/li>
1 print(es.cat.thread_pool())

Snapshot锛堝揩鐓х浉鍏筹級

  • es.snapshot.create锛屽湪瀛樺偍搴撲腑鍒涘缓蹇収銆?
    • repository瀛樺偍搴撳悕绉般€?/li>
    • snapshot蹇収鍚嶇О銆?/li>
    • body蹇収瀹氫箟銆?/li>
  • es.snapshot.delete锛屼粠瀛樺偍搴撲腑鍒犻櫎蹇収銆?/li>
  • es.snapshot.create_repository銆傛敞鍐屽叡浜枃浠剁郴缁熷瓨鍌ㄥ簱銆?/li>
  • es.snapshot.delete_repository锛屽垹闄ゅ叡浜枃浠剁郴缁熷瓨鍌ㄥ簱銆?/li>
  • es.snapshot.get锛屾绱㈡湁鍏冲揩鐓х殑淇℃伅銆?/li>
  • es.snapshot.get_repository锛岃繑鍥炴湁鍏冲凡娉ㄥ唽瀛樺偍搴撶殑淇℃伅銆?/li>
  • es.snapshot.restore锛屾仮澶嶅揩鐓с€?/li>
  • es.snapshot.status锛岃繑鍥炴湁鍏虫墍鏈夊綋鍓嶈繍琛屽揩鐓х殑淇℃伅銆傞€氳繃鎸囧畾瀛樺偍搴撳悕绉帮紝鍙互灏嗙粨鏋滈檺鍒朵负鐗瑰畾瀛樺偍搴撱€?/li>
  • es.snapshot.verify_repository锛岃繑鍥炴垚鍔熼獙璇佸瓨鍌ㄥ簱鐨勮妭鐐瑰垪琛紝濡傛灉楠岃瘉杩囩▼澶辫触锛屽垯杩斿洖閿欒娑堟伅銆?/li>

Task锛堜换鍔$浉鍏筹級

  • es.tasks.get锛屾绱㈢壒瀹氫换鍔$殑淇℃伅銆?/li>
  • es.tasks.cancel锛屽彇娑堜换鍔°€?/li>
  • es.tasks.list锛屼换鍔″垪琛ㄣ€?/li>

鏇村鐜╂硶https://elasticsearch-py.readthedocs.io/en/master/api.html

 

以上是关于Python鎿嶄綔es的主要内容,如果未能解决你的问题,请参考以下文章

鎿嶄綔绯荤粺-鎿嶄綔绯荤粺-鍐呮牳涓殑灞忓箷鎵撳嵃(涓?

鏁版嵁搴撶瑪璁?馃搾 MySQL鍩虹鎿嶄綔鍛戒护 鍒嗙被娓呮櫚

Django--鍗曡〃鎿嶄綔

鑺傜偣鎿嶄綔

pandas 鎿嶄綔-2

Stata 鐭╅樀鎿嶄綔

(c)2006-2024 SYSTEM All Rights Reserved IT常识