es:常用命令

一,查看es的相关信息:

1,查看集群的健康状态

liuhongdi@lhdpc:/usr/local/soft$ curl -X GET http://127.0.0.1:9200/_cat/health
1721810396 08:39:56 elasticsearch green 1 1 1 1 0 0 0 0 - 100.0%

2,查看状态:

liuhongdi@lhdpc:/usr/local/soft$ curl -XGET "http://127.0.0.1:9200/_cluster/state/nodes?pretty"

3, 查看统计:

liuhongdi@lhdpc:/usr/local/soft$ curl -XGET "http://127.0.0.1:9200/_cluster/stats?pretty"

4,查看es版本信息:

liuhongdi@lhdpc:/usr/local/soft$ curl -sXGET  "http://localhost:9200?pretty" 
{
  "name" : "lhdpc",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "xATHzefVR7WrDMeDcjh1Mg",
  "version" : {
    "number" : "8.14.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "2afe7caceec8a26ff53817e5ed88235e90592a1b",
    "build_date" : "2024-07-01T22:06:58.515911606Z",
    "build_snapshot" : false,
    "lucene_version" : "9.10.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

5,从命令行查看版本信息:

[root@blog eslogs]# /usr/local/soft/elasticsearch-8.14.2/bin/elasticsearch --version
warning: ignoring JAVA_HOME=/usr/local/soft/jdk-17.0.11; using ES_JAVA_HOME
Version: 8.14.2, Build: tar/2afe7caceec8a26ff53817e5ed88235e90592a1b/2024-07-01T22:06:58.515911606Z, JVM: 17.0.11

二,查看集群和结点的信息:

1,查看所有结点:

liuhongdi@lhdpc:/usr/local/soft$ curl -sXGET "http://localhost:9200/_cat/nodes?v"
ip        heap.percent ram.percent cpu load_1m load_5m load_15m node.role   master name
127.0.0.1           20          97   2    0.05    0.10     0.09 cdfhilmrstw *      lhdpc

2,查看主结点:

liuhongdi@lhdpc:/usr/local/soft$ curl -sXGET "http://localhost:9200/_cat/master?v"
id                     host      ip        node
v_c4MdklRIOu2166QxcJEw 127.0.0.1 127.0.0.1 lhdpc

三,es索引的别名

1,查看当前索引的别名:

liuhongdi@lhdpc:/usr/local/soft$ curl  -sXGET localhost:9200/_cat/aliases?v
alias     index       filter routing.index routing.search is_write_index
.security .security-7 -      -             -              -

2,添加别名:

liuhongdi@lhdpc:/usr/local/soft$ curl -XPOST 'http://localhost:9200/_aliases' -H "Content-Type: application/json" -d '{"actions" : [{ "add" : { "index" : "my_house","alias" : "house1" } }]}' 
{"acknowledged":true,"errors":false}

查看添加后的结果:

liuhongdi@lhdpc:/usr/local/soft$ curl  -sXGET localhost:9200/_cat/aliases?v
alias     index       filter routing.index routing.search is_write_index
.security .security-7 -      -             -              -
house1    my_house    -      -             -              -

3,删除别名:

 liuhongdi@lhdpc:/usr/local/soft$ curl -XPOST 'http://localhost:9200/_aliases' -H "Content-Type: application/json" -d '{"actions" : [{ "remove" : { "index" : "my_house","alias" : "house1" } }]}' 
{"acknowledged":true,"errors":false}

查看删除后的结果:

liuhongdi@lhdpc:/usr/local/soft$ curl  -sXGET localhost:9200/_cat/aliases?v
alias     index       filter routing.index routing.search is_write_index
.security .security-7 -      -             -              -

四,创建索引

1,查看索引:不存在索引库

liuhongdi@lhdpc:/usr/local/soft$ curl -X GET http://localhost:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size dataset.size

2,创建索引:

liuhongdi@lhdpc:/usr/local/soft$  curl -X PUT "localhost:9200/my_house"
{"acknowledged":true,"shards_acknowledged":true,"index":"my_house"}

3,再次查看索引:已经可以看到我们创建的索引了:

liuhongdi@lhdpc:/usr/local/soft$ curl -X GET http://localhost:9200/_cat/indices?v
health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size dataset.size
yellow open   my_house MPdYabF3SZmVAHzG2rNflQ   1   1          0            0       227b           227b         227b

 

五,从索引中获取指定id的文档:

[lhdop@blog logs]$ curl -X GET "localhost:9200/article/_doc/1?pretty"
{
  "_index" : "article",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 0,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "id" : 1,
    "title" : "环球公园",
    "descs" : "男人的快乐,这威震天也太帅了!"
  }
}

六,列出一个索引下的所有doc

[lhdop@blog ~]$ curl -X GET "localhost:9200/article/_search?pretty"
{
  "took" : 42,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 3,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "article",
        "_id" : "IA2qoJABjSB1En4hYsdX",
        "_score" : 1.0,
        "_source" : {
          "id" : 3,
          "title" : "河北石家庄房产",
          "content" : "河北石家庄房产"
        }
      },
      {
        "_index" : "article",
        "_id" : "Hg2qoJABjSB1En4hYscz",
        "_score" : 1.0,
        "_source" : {
          "id" : 1,
          "title" : "北京房产",
          "content" : "北京房产"
        }
      },
      {
        "_index" : "article",
        "_id" : "Hw2qoJABjSB1En4hYsdR",
        "_score" : 1.0,
        "_source" : {
          "id" : 2,
          "title" : "河北沧州房产",
          "content" : "河北沧州房产"
        }
      }
    ]
  }
}

 

posted @ 2024-07-24 17:19  刘宏缔的架构森林  阅读(11)  评论(0编辑  收藏  举报