Skip to content

ElasticSearch使用

ElasticSearch使用

what: ElasticSearch使用 where: centos7.6 x86 when: 2022.2.11 who: JRT why:进程冲突

1.es搭建

#单节点启动需要加-e "discovery.type=single-node"
docker run -itd --name jrt1 -e "discovery.type=single-node"  -p 9005:9200 -p 9300:9300 elasticsearch:7.17.0

2.创建索引(创建,增加数据在postman进行)

创建 put
http://1.117.176.116:9005/jrt
{
    "settings":{
        "number_of_shards":2,
        "number_of_replicas":2
    },
    "mappings":{
        "properties":{
            "id":{
                "type":"long"
            },
            "name":{
                "type":"text"
            }
        }
    }
}

列出索引

http://1.117.176.116:9003/_cat/indices?v

查索引结构

http://1.117.176.116:9003/jrt/_mapping

3.增加数据

增加 post
http://1.117.176.116:9005/jrt/_doc
{
  "id": 2,
  "name": "梨"
}

查索引的数据

http://1.117.176.116:9003/jrt/_search

4.数据导出,使用工具elasticsearch-dump

docker pull taskrabbit/elasticsearch-dump
#导出结构
docker run --rm -ti -v /data/a:/tmp c43f685c27c7 --input=http://1.117.176.116:9005/jrt  --output=/tmp/my_index_mapping.json   --type=mapping
#导出数据
docker run --rm -ti -v /data/a:/tmp c43f685c27c7  --input=http://1.117.176.116:9005/jrt --output=/tmp/elasticdump_export.json  --type=data

5.数据可视化

使用工具Dejavu
简介:Dejavu 也是一个 Elasticsearch的 Web UI 工具,其 UI界面更符合当下主流的前端页面风格,因此使用起来很方便。
开源地址:https://github.com/appbaseio/dejavu/
#获取镜像
docker pull appbaseio/dejavu
#es跨域配置
在es容器的es.yaml配置文件中增加如下几行:
http.port: 9200
http.cors.allow-origin: 'http://localhost:1358'
http.cors.enabled: true
http.cors.allow-headers: X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
http.cors.allow-credentials: true
#重启容器生效
docker restart jrt1
#搭建Dejavu
docker run -itd --name jrt3  -p 9007:1358  appbaseio/dejavu
访问:http://1.117.176.116:9007,根据网站引导输入es的地址和索引,即可和类似navicat一样查看es的该索引数据