docker es官方镜像 安装es使用

官方镜像:
docker pull docker.elastic.co/elasticsearch/elasticsearch:6.5.4
要设置/root/data/esdata可读写
docker run --name es_test_01 -p 9200:9200 -p 9300:9300 -v /root/data/esdata:/usr/share/elasticsearch/data -e ES_JAVA_OPTS="-Xms300m -Xmx300m" -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.5.4 
直接后台加-d:
docker run -d --name es_test_01 -p 9200:9200 -p 9300:9300 -v /root/data/esdata:/usr/share/elasticsearch/data -e ES_JAVA_OPTS="-Xms300m -Xmx300m" -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.5.4 
 
安装ik(版本要对应,之后重启容器):
docker exec -it xxx /bin/bash
 
docker重启:docker restart xxx
测试是否能连接:curl -X GET localhost:9200/
 
如果能连接,建立索引:/usr/bin/python3.6 /root/backend/deploy_test_server/create_test_esmapping.py 脚本如下
如果能建立索引,查询索引是否成功, curl -XGET localhost:9200/goodlook/post/_search?pretty
 
# coding=utf-8

from __future__ import print_function
from elasticsearch import Elasticsearch


# /usr/bin/python3.6 /root/backend/deploy_test_server/create_test_esmapping.py


# ES_HOSTS = ['elastic@localhost:9200']
ES_HOSTS = ['localhost:9200']
INDEX_NAME = 'goodlook'
DOC_TYPE = 'post'

es = Elasticsearch(hosts=ES_HOSTS)

# 如果存在索引先删除, 不存在可以注释掉 res = es.indices.delete(index=INDEX_NAME) request_body = { "mappings": { DOC_TYPE: { "properties": { "star": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "gender": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "age": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "scene": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "season": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "style": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "color": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "items": { "type": "nested", "properties": { "category": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "color": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "attributes": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" } } } } } } } res = es.indices.create(index=INDEX_NAME, ignore=400, body=request_body) print(" response: {}".format(res))

  

 

 
 
docker-compose写法
version: '2.0'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4
    container_name: elasticsearch
    environment:
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    volumes:
      - esdata1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - esnet
volumes:
  esdata1:
    driver: local
 
 

转载于:https://www.cnblogs.com/adamans/articles/10735628.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值