【问题标题】:Get all field names in an index elasticsearch python获取索引弹性搜索python中的所有字段名称
【发布时间】:2021-08-21 02:44:23
【问题描述】:

我正在尝试针对弹性搜索中的所有索引和字段搜索特定字符串。我能够获取所有索引并针对字符串搜索特定字段。如何获取特定索引中的字段名称列表?

    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']

此代码获取所有索引并检查文本输入中是否存在具有值的字段名称。理想情况下,我想检查所有字段。提前致谢!

【问题讨论】:

    标签: python elasticsearch


    【解决方案1】:

    试试:

    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) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-12
      • 1970-01-01
      • 1970-01-01
      • 2014-12-09
      相关资源
      最近更新 更多