将ES索引从一个集群迁移到另一个集群的python脚本
Elasticsearch • 森 发表了文章 • 2 个评论 • 2326 次浏览 • 2021-08-25 17:20
将索引从一个集群(ip:192.168.0.1)迁移到另一个集群(ip:192.168.0.2),新集群需要配置白名单:
```ymlelasticsearch.yml
reindex.remote.whitelist: ['192.168.0.1:9200']
<br /> <br />python
import json
import requests
import base64
迁移索引数据
def reindex(index):
print("{0} 索引正在迁移中".format(index))
jsonData = {
"source": {
"remote": {
"host": "<a href="http://192.168.0.1:9200"" rel="nofollow" target="_blank">http://192.168.0.1:9200",
"socket_timeout": "30s",
"connect_timeout": "30s",
"username": "elastic",
"password": "123456"
},
"index": index
},
"dest": {
"index": index
}
}
res = requests.post("<a href="http://192.168.0.2:9200/_reindex"" rel="nofollow" target="_blank">http://192.168.0.2:9200/_reindex", json=jsonData)
print(res.status_code)
print(res.content)
获取创建索引的语句
def getIndexDslJson(index):
username = "elastic"
password = "123456"
user_info_str = username + ":" + password
user_info = base64.b64encode(user_info_str.encode()) # 这个得到是个字节类型的数据
headers = {
"Authorization": "Basic {0}".format(user_info.decode()) # 这个就是需要验证的信息
}
res = requests.get("http://192.168.0.1:9200/{0}".format(index),
headers=headers)
print(res.status_code)
jsonIndex = json.loads(res.content)
print(jsonIndex[index])
del jsonIndex[index]['settings']['index']['creation_date']
del jsonIndex[index]['settings']['index']['provided_name']
del jsonIndex[index]['settings']['index']['uuid']
del jsonIndex[index]['settings']['index']['version']
jsonIndex[index]['settings']['index']['number_of_shards'] = 1
jsonIndex[index]['settings']['index']['number_of_replicas'] = 0
return jsonIndex[index]
创建索引
def createIndex(index, dslJson):
res = requests.put("http://192.168.0.2:9200/{0}".format(index), json=dslJson)
print(res.status_code)
print(res.content)
if name == 'main':需要创建的索引
indexList = [
"index1_v1", "index2_v1"
]
for index in indexList:
dslJson = getIndexDslJson(index) # 获取原索引的结构
createIndex(index, dslJson) # 根据原索引结构,在新集群创建索引
reindex(index) # 将原集群索引迁移到新集群
```
使用docker安装es环境
Elasticsearch • 森 发表了文章 • 0 个评论 • 3872 次浏览 • 2021-08-25 16:31
创建es账号并授权
```
创建账号
adduser es
修改密码
passwd es
授权
chmod -v u+w /etc/sudoers
vim /etc/sudoers
新增
es ALL=(ALL) ALL
wq保存退出,这时候要记得将写权限收回
chmod -v u-w /etc/sudoers
```
创建docker网络
<br /> docker network create tx<br />
安装Elasticsearch
<br /> docker pull elasticsearch:6.7.1<br />
<br /> 在/home/es 中创建 config,data,plugins目录<br /> 在plugins目录中下载es相关插件,如:ik,pinyin等<br /> 在config中创建elasticsearch.yml配置,创建analysis\synonym.txt 同义词<br /> 给data配置权限 sudo chmod 777 /home/es/data/<br /> 将/home/es 目录及其子目录的用户改为es:chown -R es:root /home/es/<br />
```yml
elasticsearch.yml
cluster.name: "my-docker-cluster"
node.name: "es-node1"
network.host: 0.0.0.0
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: "Authorization,X-Requested-With,Content-Length,Content-Type"
node.master: true
reindex.remote.whitelist: ['other:9200']
xpack.security.enabled: true
xpack.security.authc.api_key.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
<br /> <br /> <br /> <br />
docker run -d --net tx --name my_elasticsearch -p 9201:9200 -p 9301:9300 -v /home/es/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /home/es/config/analysis:/usr/share/elasticsearch/config/analysis -v /home/es/config/elastic-certificates.p12:/usr/share/elasticsearch/config/elastic-certificates.p12 -v /home/es/data:/usr/share/elasticsearch/data -v /home/es/plugins:/usr/share/elasticsearch/plugins -e "discovery.type=single-node" -i -t --privileged=true elasticsearch:6.7.1
```
安装kibana
<br /> docker pull kibana:6.7.1<br />
```yml
kibana.yml配置文件
server.name: kibana
server.host: 0.0.0.0
elasticsearch.hosts: ["<a href="http://my_elasticsearch:9200"" rel="nofollow" target="_blank">http://my_elasticsearch:9200"]
i18n.locale: "zh-CN"
elasticsearch.username: "elastic"
elasticsearch.password: "123456"
xpack.graph.enabled : true
xpack.ml.enabled : true
xpack.monitoring.enabled : true
xpack.reporting.enabled : true
xpack.security.enabled : true
xpack.watcher.enabled : true
<br /> <br />
docker run -d --name kibana --net tx -p 5601:5601 -v /home/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml kibana:6.7.1
```
Kibana 中用公式和时间旅行回答的 10 个常见问题
Kibana • liuxg 发表了文章 • 0 个评论 • 2105 次浏览 • 2021-08-25 13:12
此外,在时间和空间中移动和重放数据是获取历史背景和了解关于现在的更多见解的有效方法。
在以下部分中,你将找到 10 个问题示例,你可以通过公式、时移和及时浏览数据,使用 Kibana 中的仪表板数据和地图可视化来回答这些问题。 尝试跟随你自己的数据或使用 Kibana 的示例数据集。 有问题吗? 前往我们的讨论论坛。
在名单上:
错误的比例在增加吗?
表现与上周相比如何?
这些数据与同行相比如何?
对我的平均水平影响最大的是什么?
与历史相比,原始收益/损失是多少?
收益/损失占过去业绩的百分比是多少?
数据是如何到达现在的位置的?
如何以交互方式探索空间中的仪表板?
这个指标的单位版本是什么?
我对上一时期的行业特定计算(例如“净推荐值”)是什么?
https://elasticstack.blog.csdn ... 83729
使用logstash的http-poller input插件获取的数据怎么保存到 elasticsearch
Logstash • tongchuan1992 回复了问题 • 2 人关注 • 1 个回复 • 1991 次浏览 • 2021-08-24 16:21
kibana中创建一个用户a,用户a登录报错
Kibana • tongchuan1992 回复了问题 • 2 人关注 • 1 个回复 • 2447 次浏览 • 2021-08-24 16:43
ES 上传时跟已存在的文档进行替换或去重
Elasticsearch • Tsukiand 回复了问题 • 3 人关注 • 2 个回复 • 1670 次浏览 • 2021-08-24 20:48
es如何先distinct某些字段再group其中的部分字段?
Elasticsearch • lijianghu 回复了问题 • 2 人关注 • 1 个回复 • 2420 次浏览 • 2021-08-23 18:04
社区日报 第1289期 (2021-08-21)
社区日报 • bsll 发表了文章 • 1 个评论 • 1501 次浏览 • 2021-08-21 17:05
1.lucene倒排索引结构
[https://zhuanlan.zhihu.com/p/81761278](https://zhuanlan.zhihu.com/p/81761278)
2.lucene fst原理解析
[https://www.shenyanchao.cn/blo ... -fst/](https://www.shenyanchao.cn/blo ... e-fst/)
3.es如何在使用别的字段排序时仍然计算_score分数
[https://stackoverflow.com/ques ... rting](https://stackoverflow.com/ques ... orting)
elasticsearch threadpool 每天定时出现load高
Elasticsearch • Charele 回复了问题 • 2 人关注 • 1 个回复 • 1663 次浏览 • 2021-08-21 13:51
logstash配置out自定义模板到ES失败,大神们帮忙分析下什么原因吧
回复Logstash • a505100745 发起了问题 • 1 人关注 • 0 个回复 • 2883 次浏览 • 2021-08-20 17:24
logstash http_poller body 转义双引号和单引号
回复Logstash • zhuyangping 回复了问题 • 1 人关注 • 1 个回复 • 2570 次浏览 • 2021-08-24 14:32
Elastic:如何使用 Elasticsearch PHP 客户端创建简单的搜索引擎
Elasticsearch • liuxg 发表了文章 • 0 个评论 • 1506 次浏览 • 2021-08-20 11:32
原文链接:https://blog.csdn.net/UbuntuTo ... 02174
原文链接:https://blog.csdn.net/UbuntuTo ... 02174
关于nested多层嵌套,如何让子nested搜索按分组来搜
Elasticsearch • star_xu 回复了问题 • 2 人关注 • 5 个回复 • 1683 次浏览 • 2021-09-10 09:26
es7.6.2 排序时间过长问题
Elasticsearch • xieqiao 回复了问题 • 3 人关注 • 2 个回复 • 1954 次浏览 • 2021-08-19 20:53

