课程环境
Elasticsearch 介绍
Elasticsearch 索引简单操作

- 查询集群健康状况:
GET /_cat/health?v
- 查询集群中有哪些索引:
GET /_cat/indices?v
- 简单的索引操作:
- 新增索引:
PUT /product_index
- 删除指定索引:
DELETE /product_index
- 删除指定多个索引:
DELETE /product_index,order_index
- 删除匹配符索引:
DELETE /product_*
- 删除所有索引:
DELETE /_all
- 查询索引配置信息:
GET /product_index/_settings
- 查询多个索引配置信息:
GET /product_index,order_index/_settings
- 查询所有索引配置信息:
GET /_all/_settings
Elasticsearch 索引较复杂操作
- 新增索引,并指定 primary shards 和 replica shards 数量。
PUT /order_index
{
"settings": {
"index": {
"number_of_shards": 5,
"number_of_replicas": 1
}
}
}
- 新增完索引后,更改 replica shards 数量:
PUT /order_index/_settings
{
"number_of_replicas": 2
}
- 新增索引并设置 mapping(Dynamic Mapping):
- mapping 你可以理解为是传统数据库中的设置表结构一样的作用,比如有个字段叫做 introduce,传统数据库文本字段你会考虑设置为:char、varchar、text,是否为空,是否有默认值等。
- Elasticsearch 中的 mapping 类似上面,因为你一样要考虑比如这个字段:article_title 是否设置为 text 类型,要不要分词等。
- 下面的 mapping 使用了 ik 分词器(5.2.0 版本)。field 新增后是不能修改的。
PUT /product_index
{
"settings": {
"refresh_interval": "5s",
"number_of_shards": 5,
"number_of_replicas": 1
},
"mappings": {
"product": {
"properties": {
"id": {
"type": "text",
"index": "not_analyzed"
},
"product_name": {
"type": "text",
"store": "no",
"term_vector": "with_positions_offsets",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"boost": 5
},
"product_desc": {
"type": "text",
"index": "not_analyzed"
},
"price": {
"type": "double",
"index": "not_analyzed"
},
"created_date_time": {
"type": "date",
"index": "not_analyzed",
"format": "basic_date_time"
},
"last_modified_date_time": {
"type": "date",
"index": "not_analyzed",
"format": "basic_date_time"
},
"version": {
"type": "long",
"index": "no"
}
}
}
}
}