Получить все имена полей в индексеasticsearch python - PullRequest
0 голосов
/ 02 марта 2020

Я пытаюсь найти конкретную строку по всем индексам и полям в elasti c search. Я смог получить все индексы и найти конкретное поле по строке. Как получить список имен полей в определенном индексе?

    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. В идеале я хочу проверить все поля. Заранее спасибо!

1 Ответ

2 голосов
/ 02 марта 2020

Попробуйте:

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) 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...