Node.js/ElasticSearch:修订间差异
来自康健生活
创建页面,内容为“== 引言 == ElasticSearch,[https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html 文档]” |
|||
| (未显示同一用户的8个中间版本) | |||
| 第1行: | 第1行: | ||
== 引言 == | == 引言 == | ||
ElasticSearch,[https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html 文档] | ElasticSearch,[https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html 文档] | ||
服务器安装 elasticsearch 需要依赖 java | |||
{{Shc|<syntaxhighlight lang="bash"> | |||
yum install java -y | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
{{Shc_out|<syntaxhighlight lang="bash">java -version | |||
</syntaxhighlight>|<syntaxhighlight lang="bash">openjdk version "1.8.0_262" | |||
OpenJDK Runtime Environment (build 1.8.0_262-b10) | |||
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode) | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
下载并安装 GPG key | |||
{{shc|<syntaxhighlight lang="bash">rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
添加 yum 仓库 | |||
{{shc|<syntaxhighlight lang="bash">vi /etc/yum.repos.d/elasticsearch.repo | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
{{hc|head=/etc/yum.repos.d/elasticsearch.repo|output=<syntaxhighlight lang="bash">[elasticsearch-7.x] | |||
name=Elasticsearch repository for 7.x packages | |||
baseurl=https://artifacts.elastic.co/packages/7.x/yum | |||
gpgcheck=1 | |||
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch | |||
enabled=1 | |||
autorefresh=1 | |||
type=rpm-md | |||
</syntaxhighlight>}} | |||
安装 elasticsearch | |||
{{shc|<syntaxhighlight lang="bash">yum install elasticsearch | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
== 迁移 == | |||
=== elasticdump === | |||
{{shc|<syntaxhighlight lang="bash"> | |||
npm install elasticdump</syntaxhighlight>|$|/home/kangkk}} | |||
导出数据 | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
./node_modules/elasticdump/bin/elasticdump --input http://用户名:密码@IP:端口/索引名称 --output ./索引名称_mapping.json --type=mapping</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
Fri, 28 May 2021 10:59:42 GMT | starting dump | |||
Fri, 28 May 2021 10:59:42 GMT | got 1 objects from source elasticsearch (offset: 0) | |||
Fri, 28 May 2021 10:59:42 GMT | sent 1 objects to destination file, wrote 1 | |||
Fri, 28 May 2021 10:59:42 GMT | got 0 objects from source elasticsearch (offset: 1) | |||
Fri, 28 May 2021 10:59:42 GMT | Total Writes: 1 | |||
Fri, 28 May 2021 10:59:42 GMT | dump complete | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
./node_modules/elasticdump/bin/elasticdump --input http://用户名:密码@IP:端口/索引名称 --output ./索引名称.json --type=data | |||
</syntaxhighlight>|<syntaxhighlight lang="bash">Fri, 28 May 2021 11:00:01 GMT | starting dump | |||
Fri, 28 May 2021 11:00:01 GMT | got 100 objects from source elasticsearch (offset: 0) | |||
Fri, 28 May 2021 11:00:01 GMT | sent 100 objects to destination file, wrote 100 | |||
Fri, 28 May 2021 11:00:02 GMT | got 100 objects from source elasticsearch (offset: 100) | |||
Fri, 28 May 2021 11:00:02 GMT | sent 100 objects to destination file, wrote 100 | |||
... | |||
Fri, 28 May 2021 11:00:32 GMT | sent 55 objects to destination file, wrote 55 | |||
Fri, 28 May 2021 11:00:32 GMT | got 0 objects from source elasticsearch (offset: 3455) | |||
Fri, 28 May 2021 11:00:32 GMT | Total Writes: 3455 | |||
Fri, 28 May 2021 11:00:32 GMT | dump complete | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
导入数据,创建索引 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
curl -XPUT http://账号:密码@IP:端口/索引名称</syntaxhighlight>|$|/home/kangkk}} | |||
开始导入 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
./node_modules/elasticdump/bin/elasticdump --input ./索引名称_mapping.json --output http://账号:密码@IP:端口/ --type=mapping | |||
./node_modules/elasticdump/bin/elasticdump --input ./索引名称.json --output http://账号:密码@IP:端口/ --type=data | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
=== taskrabbit/elasticsearch-dump === | |||
=== 其他 === | |||
查看索引大小。 | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
curl -X GET http://账号:密码@IP:端口/_cat/indices?v</syntaxhighlight>|<syntaxhighlight lang="bash"> | |||
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size | |||
green open .security-7 aGvmk0RpT0CJXkB46wN-lg 1 0 44 0 77.2kb 77.2kb | |||
green open .kibana_task_manager_1 7E4IiOYTTHiPhzqVsE29ug 1 0 2 0 6.6kb 6.6kb | |||
green open .apm-agent-configuration BEkeof_DQ8mtnbfn2PWwQA 1 0 0 0 283b 283b | |||
yellow open 某个索引 kinMZdbPRSenXvSxeBewzA 1 1 3455 0 931.9kb 931.9kb | |||
green open .kibana_1 WaiT4ix5RbOJV5Z_VOl92g 1 0 33 6 72.3kb 72.3kb | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
== error == | |||
* <code>Error Emitted => {"root_cause":[{"type":"mapper_parsing_exception","reason":"analyzer [ik_smart] not found for field [title]"}],"type":"mapper_parsing_exception","reason":"analyzer [ik_smart] not found for field [title]"}</code> | |||
: 没有安装IK分词器(elasticsearch-analysis-ik) | |||
== 配置 == | |||