[英]Get all field names in an index elasticsearch python
我正在嘗試針對彈性搜索中的所有索引和字段搜索特定字符串。 我能夠獲取所有索引並針對字符串搜索特定字段。 如何獲取特定索引中的字段名稱列表?
def check_name_query(self):
es = Elasticsearch("http://localhost:9200")
indexlist = es.indices.get_alias()
print "indices:", indexlist
text_val = self.textin.text
for ind in es.indices.get('*'):
print ind
res = es.search(index=ind, body={'query': {'wildcard': {'name': "*" + text_val + "*"}}})
print res['hits']['hits']
此代碼獲取所有索引並檢查是否存在具有 textinput 值的字段名稱。 理想情況下,我想檢查所有領域。 提前致謝!
嘗試:
from elasticsearch import Elasticsearch
es = Elasticsearch()
indices_names = []
for elem in es.cat.indices(format="json"):
indices_names.append( elem['index'] )
dict_index_fields = {}
for index in indices_names:
mapping = es.indices.get_mapping(index)
dict_index_fields[index] = []
for field in mapping[index]['mappings']['properties']:
dict_index_fields[index].append(field)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.