• elasticSearch的部署和使用


    部署服务

    docker run启动elastic服务

    docker pull elasticsearch:6.7.2
    
    docker run -d -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:6.7.2
    
    

    docker-compose.yml的方式部署

    version: '2.2'
    services:
      elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.7.2
        container_name: elasticsearch
        environment:
          - cluster.name=docker-cluster
          - bootstrap.memory_lock=true
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - esdata1:/usr/share/elasticsearch/data
        ports:
          - 9200:9200
        networks:
          - esnet
      elasticsearch2:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.7.2
        container_name: elasticsearch2
        environment:
          - cluster.name=docker-cluster
          - bootstrap.memory_lock=true
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
          - "discovery.zen.ping.unicast.hosts=elasticsearch"
        ulimits:
          memlock:
            soft: -1
            hard: -1
        volumes:
          - esdata2:/usr/share/elasticsearch/data
        networks:
          - esnet
    
    volumes:
      esdata1:
        driver: local
      esdata2:
        driver: local
    
    networks:
      esnet:
    

    elastic常用命令

    查看集群是否健康

      curl 'localhost:9200/_cat/health?v'
    

    获取集群的节点列表

      curl 'localhost:9200/_cat/nodes?v'
    

    列出所有索引

    curl 'localhost:9200/_cat/indices?v'
    

    建立名为customer的索引

     curl -XPUT 'localhost:9200/customer?pretty'
    
    

    向索引customer,类型为external,添加数据

      curl -XPUT 'localhost:9200/customer/external/1?pretty' -d '
      {
               "name": "John Doe"
      }'
    

    获取数据

    获取customer索引下类型为external,id为1的数据,pretty参数表示返回结果格式美观。

       curl -XGET 'localhost:9200/customer/external/1?pretty'
    

    删除索引 DELETE

    curl -XDELETE 'localhost:9200/customer?pretty'
    

    修改数据,如果不存在,就新增

    curl -XPUT 'localhost:9200/customer/external/1?pretty' -d '
      {
    
        "name": "John Doe"
    
      }'
    

    更新数据

      curl -XPOST 'localhost:9200/customer/external/1/_update?pretty' -d '
      {
    
        "doc": { "name": "Jane Doe", "age": 20 }
      }'
    

    删除一条记录数据

    curl -XDELETE 'localhost:9200/customer/external/2?pretty'
    
  • 相关阅读:
    禁止进入activity自动弹出键盘
    sqlite的limit使用
    关于anroid设置webview背景方法探讨(转)
    遍历ListView,查出每一项的内容
    虚拟机网络不通故障解决
    zabbix第一篇:zabbix安装及使用
    ansible使用1
    PS1修改xshell命令行样式
    手动配置网卡配置文件ifcfg-eth0
    Linux虚拟机centos系统安装
  • 原文地址:https://www.cnblogs.com/lori/p/11384635.html
Copyright © 2020-2023  润新知