ES-Index索引入门

  • 虽然直接 PUT 数据,ES 就会为我们创建索引并且动态建立映射
  • 但是为了方便维护,我们需要手动建立索引和映射
  • 就像数据库的建表语句一样,即使 Hibernatejpa 已经给我们提供了自动建表的功能
  • 我们实际开发中依然是手动建表

创建索引

  • 语法如下:
PUT /index

{
    "settings":{
        "number_of_shards":1,
        "number_of_replicas":1
    },
    "mappings":{
        "properties":{
            "content":{
                "type":"text",
                "analyzer":"ik_max_word",
                "search_analyzer":"ik_smart"
            }
        }
    },
    "aliases":{
        "hhhh":{

        }
    }
}
  • aliases 是别名,我们可以使用索引名称查询,也可以使用别名来进行查询

查询索引

  • 语法如下:
GET /my_index
GET /my_index/_mapping
GET /my_index/_setting

修改索引

  • 语法如下:
  • 修改 settings
PUT /my_index/_settings
{
    "index":{
        "number_of_replicas":2
    }
}

删除索引

  • 语法如下:
DELETE /my_index
DELETE /index_one,index_two
DELETE /index_*
DELETE /_all

  • 为了安全起见,防止恶意删除索引,删除时必须指定 索引名
  • 修改 elasticsearch.yml 配置一下即可
action.destructive_requires_name: true

posted @ 2020-10-16 10:17  BNTang  阅读(949)  评论(0)    收藏  举报