# -*- coding:utf-8 -*-
__auther__ = "光叶水青冈"
import requests, json
def get_index(full_elastic_url):
return json.loads(requests.get(full_elastic_url + "/_mapping").content.decode())
def repalce(url,options=None):
data = get_index(url)
for da in data:
# 索引修改
if options:
if options == str(da):
fields = data.get(da)['mappings']['properties']
cont = 1
for field in fields:
tp = fields.get(field)
if tp.get("type") == "text":
Data = {"properties": {
"{}".format(field): {
"type": "text",
"fields": {"keyword": {"type": "keyword",
"ignore_above": 256
}
},
"fielddata": True
}
}
}
HEAD = {
"Content-Type": "application/json"
}
result = requests.put(url=url + da + "/_mapping/", data=json.dumps(Data),
headers=HEAD).content.decode()
print("完成{}的第{}个text字段修改‘{}’".format(str(da),cont, field),result)
cont += 1
pass
if __name__ == '__main__':
"""
批量修改elastic text类型字段
# """
url = "http://*.*.*.*:9200"
repalce(url,"***-pro-2020")
repalce(url,"******-pro-2020")
批量修改elastic text类型字段
最新推荐文章于 2023-05-10 09:38:46 发布