Elasticsearch (二) 索引

Elasticsearch 官方使用手册>>

模拟需求:

  • 一个新闻
  • 可以进行新闻检索

数据库设计

Tab:news_info

| id | news_type | title | content | author | create_time | read_number |

新建索引

//格式
[GET] http://host:port/索引名称
//例如
[GET] http://host:port/news
//返回
{
    "acknowledged": true, 
    "shards_acknowledged": true,
    "index": "news_box"
}

查看索引

//格式
[GET] http://host:port/索引名称/_settings
//例如
[GET] http://host:port/news/_settings
//返回
{
    "news": {
        "settings": {
            "index": {
                "creation_date": "1578991439484",
                "number_of_shards": "5",
                "number_of_replicas": "1",
                "uuid": "bGscXThhSuSTJhG6t4KfGg",
                "version": {
                    "created": "6080699"
                },
                "provided_name": "news"
            }
        }
    }
}

查看多个索引

//格式
[GET] http://host:port/索引名称1,索引名称1/_settings #查看多个索引
[GET] http://host:port/_all/_settings #查看所有索引 //例如 [GET] http://host:port/news,news2/_settings //返回 { "news2": { "settings": { "index": { "creation_date": "1578991693537", "number_of_shards": "5", "number_of_replicas": "1", "uuid": "axD970x6TrOL-LATe5Vhdg", "version": { "created": "6080699" }, "provided_name": "news2" } } }, "news": { "settings": { "index": { "creation_date": "1578991439484", "number_of_shards": "5", "number_of_replicas": "1", "uuid": "bGscXThhSuSTJhG6t4KfGg", "version": { "created": "6080699" }, "provided_name": "news" } } } }

删除索引

//格式
[DELETE] http://host:port/索引名称
//例如
[DELETE] http://host:port/news
//返回
{
    "acknowledged": true
}

关闭索引

//格式
[POST] http://host:port/索引名称/_close
//例如
[POST] http://host:port/news/_close
//返回
{
    "acknowledged": true
}

打开索引

//格式
[POST] http://host:port/索引名称/_open
//例如
[POST] http://host:port/news/_open
//返回
{
    "acknowledged": true,
    "shards_acknowledged": true
}
原文地址:https://www.cnblogs.com/devan/p/12193016.html