暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

ElasticSearch命令总结

DevOps运维技术栈 2021-05-16
780
ElasticSearch常用命令(ElastciSearch6.x/7.x)

带账号密码访问

    curl -XGET -u admin:password 'http://192.168.100.11:9200/_license'  // 查看证书类型,带密码访问
    复制

    无密码访问:

      # 本文博客地址:https://blog.csdn.net/knight_zhou/article/details/103687510
      http://192.168.100.11:9200/_xpack/license/start_basic?acknowledge=true  //通过postman进行请求改为basic模式
      curl 'IP:9200/_cat/health?v'  // health
      curl 'IP:9200/_cat/nodes?v'   // node
      curl -XDELETE 'k.cn:9200/xxoo?pretty'  // delete index
      curl -XGET 'http://k.cn:9200/test-blog/_settings'  // 查询index的setting
      curl -XGET 'http://k.cn:9200/test-blog/_mappings'。 // 查询index的mapping
      POST kibana_sample_data_logs/_delete_by_query?refresh?{"query":{"match_all": {}}}    // 删除索引下的所有数据
      复制

      创建索引

        curl -XPUT '127.0.0.1:9200/ccdd?pretty'  # 创建索引,默认是2个分片 一个副本
        curl '127.0.0.1:9200/_cat/indices?v'  #查询所有索引及数据大小
        复制

        向指定索引新增文档:

          curl -X PUT "localhost:9200/xxoo/_doc/1" -H 'Content-Type:application/json' -d' {
          "user" : "tom",
          "message" : "hello world"
          }'


          curl -X PUT "localhost:9200/xxoo/_doc/2" -H 'Content-Type:application/json' -d' {
          "user" : "nick",
          "message" : "你好"
          }'


          复制

          查询文档

            curl -XGET 127.0.0.1:9200/xxoo/_search |jq .    # 查询索引下的全部文档
            curl -XGET 127.0.0.1:9200/xxoo/_doc/1 |jq .    # 根据id检索某个文档
            curl -XGET 127.0.0.1:9200/xxoo/_search?q=user:tom|jq .   # 条件查询
            复制

            更新文档(指定 _id
            )

              curl -X PUT "localhost:9200/xxoo/_doc/2" -H 'Content-Type:application/json' -d' {
              "user" : "tom",
              "message" : "hello world"
                }'
              复制

              删除文档

                curl -XDELETE 127.0.0.1:9200/xxoo/_doc/2    # 删除id为2的索引
                复制

                创建索引指定分片数和副本数

                  curl -XPUT 'http://k.cn:9200/studentindex' -d'
                  {
                  "settings" : {
                  "index" : {
                  "number_of_shards" : 3,
                  "number_of_replicas" : 2
                  }
                  }
                  }'


                  复制


                  查询索引是studentindex,type是student,studentname字段的值是“李”的信息

                  get查询:

                    curl -XGET 'http://k.cn:9200/studentindex/student/_search?q=studentname:李'
                    复制

                    post查询:

                      curl -X POST \
                      'http://localhost:9200/studentindex/student/_search' -d '{
                      "query": {
                      "match": {
                      "studentname": "李"
                      }
                      },
                      "from": 100, // 第几页开始
                      "size": 10 // 每页的大小
                      }'
                      复制


                      文章转载自DevOps运维技术栈,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                      评论