ElasticSearch 7 学习(2)索引基本操作

查看基本信息

localhost:9200

{
  "name" : "node-1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "Yw4Baaw9S72T8KqsuiOs9Q",
  "version" : {
    "number" : "7.1.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "606a173",
    "build_date" : "2019-05-16T00:43:15.323135Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

创建索引 PUT请求

  • 请求
localhost:9200/nba
  • 响应
{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "nba"
}

查看索引 GET请求

  • 请求
localhost:9200/nba
  • 响应
{
    "nba": {
        "aliases": {},  // 别名
        "mappings": {}, // 表结构
        "settings": {   // 索引设置
            "index": {  // 创建时间
                "creation_date": "1573278626713",
                "number_of_shards": "1",    // 分片数量
                "number_of_replicas": "1",  // 副本数量
                "uuid": "eeQmIsZ8Tl-GJ-xpFuOirg",   // UUID 索引的唯一ID
                "version": {
                    "created": "7020199"
                },
                "provided_name": "nba"
            }
        }
    }
}

删除索引 DELETE请求

  • 请求
localhost:9200/nba
  • 响应
{
    "acknowledged": true
}

批量获取索引 GET请求

  • 请求
localhost:9200/cba,nba
  • 响应
{
    "cba": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1573281458107",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "uuid": "ikxZrzk2TVqQn7zRi2_glw",
                "version": {
                    "created": "7020199"
                },
                "provided_name": "cba"
            }
        }
    },
    "nba": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1573281355145",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "uuid": "hkhv1WKSQqWil3P9UXt3Aw",
                "version": {
                    "created": "7020199"
                },
                "provided_name": "nba"
            }
        }
    }
}

获取全部索引 GET请求

  • 请求
localhost:9200/_all
  • 响应
{
    "cba": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1573281458107",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "uuid": "ikxZrzk2TVqQn7zRi2_glw",
                "version": {
                    "created": "7020199"
                },
                "provided_name": "cba"
            }
        }
    },
    "nba": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1573281355145",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "uuid": "hkhv1WKSQqWil3P9UXt3Aw",
                "version": {
                    "created": "7020199"
                },
                "provided_name": "nba"
            }
        }
    }
}

使用_cat获取全部索引 GET请求

  • 请求
localhost:9200/_cat/indices?v
  • 响应
health status index                uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   .kibana_task_manager YA0slSRkRJqrE_jF0aOlFA   1   0          2            0     45.5kb         45.5kb
yellow open   cba                  ikxZrzk2TVqQn7zRi2_glw   1   1          0            0       230b           230b
yellow open   nba                  hkhv1WKSQqWil3P9UXt3Aw   1   1          0            0       283b           283b
green  open   .kibana_1            579wwXgCQJKJU1Ge7cJVXw   1   0          4            1       24kb           24kb

判断索引是否存在 HEAD请求

  • 请求
localhost:9200/nba
  • 响应
状态码"200"则为存在,不存在则为"404"

关闭索引不删除 POST请求

  • 请求
localhost:9200/nba/_close
  • 响应
{
    "acknowledged": true,
    "shards_acknowledged": true
}

打开索引 POST请求

  • 请求
localhost:9200/nba/_open
  • 响应
{
    "acknowledged": true,
    "shards_acknowledged": true
}

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/12/elasticsearch-7-learning-basic-index-operations/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
ElasticSearch 7 学习(2)索引基本操作
查看基本信息 localhost:9200 { "name" : "node-1", "cluster_name" : "elasticsearch", "cluster_uuid……
<<上一篇
下一篇>>
文章目录
关闭
目 录