Notice: 函数 WP_Scripts::localize 的调用方法不正确$l10n 参数必须是一个数组。若要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。 请查阅调试 WordPress来获取更多信息。 (这个消息是在 5.7.0 版本添加的。) in /data/www/appblog/wp-includes/functions.php on line 6131

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
}
上一篇 ElasticSearch 7 学习(1)基本概念
下一篇 ElasticSearch 7 学习(3)映射的介绍与使用