一.關於別名的操作
- es.indices.put_alias,為一個或多個索引創建別名,查詢多個索引的時候,可以使用這個別名
print(es.indices.put_alias(index='p3', name='p3_alias')) # 為單個索引創建別名 print(es.indices.put_alias(index=['p3', 'p2'], name='p23_alias')) # 為多個索引創建同一個別名,聯查用
- es.indices.delete_alias,刪除一個或多個別名
#必須指定索引和要刪除的別名,因為一個索引可能對應多個別名 index和name的參數必須同時傳入 pprint(es.indices.delete_alias(index=['person'],name='wocao')) #{'acknowledged': True} pprint(es.indices.delete_alias(index=['person','person1'],name='wocao')) #{'acknowledged': True}
- es.indices.get_alias,查詢索引所存在的別名
print(es.indices.get_alias(index=['person1'])) #{'person1': {'aliases': {'wocao': {}}}} print(es.indices.get_alias(index=['p2', 'p3']))
- es.indices.exists_alias,判斷一個索引是否存在某個別名
print(es.indices.exists_alias(name='wocao',index='person')) #True
二. 查看索引的相關配置
es.indices.get_mapping,檢索索引或索引/類型的映射定義
pprint(es.indices.get_mapping(index='person'))
es.indices.get_settings,檢索一個或多個(或所有)索引的設置。
pprint(es.indices.get_settings(index='person'))
es.indices.get,允許檢索有關一個或多個索引的信息。
print(es.indices.get(index='person')) # 查詢指定索引是否存在 print(es.indices.get(index=['person', 'person1']))
結果:
{'person': {'aliases': {'wocao': {}}, 'mappings': {'properties': {'age': {'type': 'long'}, 'name': {'fields': {'keyword': {'ignore_above': 256, 'type': 'keyword'}}, 'type': 'text'}, 'sex': {'fields': {'keyword': {'ignore_above': 256, 'type': 'keyword'}}, 'type': 'text'}}}, 'settings': {'index': {'creation_date': '1589706232019', 'number_of_replicas': '1', 'number_of_shards': '1', 'provided_name': 'person', 'uuid': 'ZfGU_CCbSdq-7dtqdxrLWA', 'version': {'created': '7010199'}}}}, 'person1': {'aliases': {}, 'mappings': {'properties': {'age': {'type': 'long'}, 'name': {'fields': {'keyword': {'ignore_above': 256, 'type': 'keyword'}}, 'type': 'text'}, 'sex': {'fields': {'keyword': {'ignore_above': 256, 'type': 'keyword'}}, 'type': 'text'}}}, 'settings': {'index': {'creation_date': '1589719495845', 'number_of_replicas': '1', 'number_of_shards': '1', 'provided_name': 'person1', 'uuid': 'P8KAm08JRseulsYoQ5pEYw', 'version': {'created': '7010199'}}}}}
es.indices.get_field_mapping,檢索特定字段的映射信息。
pprint(es.indices.get_field_mapping(fields=['age','name'], index='person'))
結果:
{'person': {'mappings': {'age': {'full_name': 'age', 'mapping': {'age': {'type': 'long'}}}, 'name': {'full_name': 'name', 'mapping': {'name': {'fields': {'keyword': {'ignore_above': 256, 'type': 'keyword'}}, 'type': 'text'}}}}}}
其他操作:
- es.indices.exists_type,檢查索引/索引中是否存在類型/類型。
- es.indices.flush,明確的刷新一個或多個索引。
- es.indices.get_template,按名稱檢索索引模板。
- es.indices.open,打開一個封閉的索引以使其可用於搜索。
- es.indices.close,關閉索引以從群集中刪除它的開銷。封閉索引被阻止進行讀/寫操作。
- es.indices.clear_cache,清除與一個或多個索引關聯的所有緩存或特定緩存。
- es.indices.get_uprade,監控一個或多個索引的升級程度。
- es.indices.put_mapping,注冊特定類型的特定映射定義。
- es.indices.put_settings,實時更改特定索引級別設置。
- es.indices.put_template,創建一個索引模板,該模板將自動應用於創建的新索引。
- es.indices.rollove,當現有索引被認為太大或太舊時,翻轉索引API將別名轉移到新索引。API接受單個別名和條件列表。別名必須僅指向單個索引。如果索引滿足指定條件,則創建新索引並切換別名以指向新別名。
- es.indices.segments,提供構建Lucene索引(分片級別)的低級別段信息
三.cat查詢
- es.cat.aliases,返回別名信息。
# 查詢別名為wocao的索引的索引名字 print(es.cat.aliases(name='person')) #wocao person - - - #wocao person1 - - - print(es.cat.aliases(name='person', format='json')) #[{'alias': 'wocao', 'index': 'person', 'filter': '-', 'routing.index': '-', 'routing.search': '-'}, {'alias': 'wocao', 'index': 'person1', 'filter': '-', 'routing.index': '-', 'routing.search': '-'}]
- es.cat.allocation,返回分片使用情況。
print(es.cat.allocation()) print(es.cat.allocation(node_id=['node1'])) print(es.cat.allocation(node_id=['node1', 'node2'], format='json'))
- es.cat.count,Count提供對整個群集或單個索引的文檔計數的快速訪問。
print(es.cat.count()) # 集群內的文檔總數 print(es.cat.count(index='p3')) # 指定索引文檔總數 print(es.cat.count(index=['p3', 'p2'], format='json')) # 返回兩個索引文檔和
-
es.cat.fielddata,基於每個節點顯示有關當前加載的fielddata的信息。有些數據為了查詢效率,會放在內存中,fielddata用來控制哪些數據應該被放在內存中,而這個es.cat.fielddata則查詢現在哪些數據在內存中,數據大小等信息。
1 print(es.cat.fielddata()) 2 print(es.cat.fielddata(format='json', bytes='b'))
1 bytes 單位'b','k','kb','m','mb','g','gb','t','tb' ,'p','pb'
- es.cat.health,從集群中health里面過濾出簡潔的集群健康信息
1 print(es.cat.health()) 2 print(es.cat.health(format='json'))
- es.cat.help,返回es.cat的幫助信息。
1 print(es.cat.help())
- es.cat.indices,返回索引的信息。
1 print(es.cat.indices()) 2 print(es.cat.indices(index='p3')) 3 print(es.cat.indices(index='p3', format='json'))
- es.cat.master,返回集群中主節點的IP,綁定IP和節點名稱。
1 print(es.cat.master()) 2 print(es.cat.master(format='json'))
- es.cat.nodeattrs,返回節點的自定義屬性。
1 print(es.cat.nodeattrs()) 2 print(es.cat.nodeattrs(format='json'))
- es.cat.nodes,返回節點的拓撲,這些信息在查看整個集群時通常很有用,特別是大型集群。我有多少符合條件的節點?
1 print(es.cat.nodes()) 2 print(es.cat.nodes(format='json'))
- es.cat.plugins,返回節點的插件信息。
1 print(es.cat.plugins()) 2 print(es.cat.plugins(format='json'))
- es.cat.segments,返回每個索引的Lucene有關的信息。
1 print(es.cat.segments()) 2 print(es.cat.segments(index='p3')) 3 print(es.cat.segments(index='p3', format='json'))
- es.cat.shards,返回哪個節點包含哪些分片的信息。
1 print(es.cat.shards()) 2 print(es.cat.shards(index='p3')) 3 print(es.cat.shards(index='p3', format='json'))
- es.cat.thread_pool,獲取有關線程池的信息。
1 print(es.cat.thread_pool())
轉自:https://www.cnblogs.com/Alexephor/p/11398060.html
更多玩法https://elasticsearch-py.readthedocs.io/en/master/api.html