目录
article
Elasticsearch Dev Tools 常用命令
Elasticsearch Dev Tools 常用命令
创建索引
PUT /index-name/
{
"mappings": {
"novel": {
"properties": {
"author": {
"type": "text",
"analyzer": "smartcn"
},
"brief": {
"type": "text",
"analyzer": "smartcn"
},
"createTime": {
"type": "date"
},
"latestChapterTitle": {
"type": "text",
"analyzer": "smartcn"
},
"title": {
"type": "text",
"analyzer": "smartcn"
},
"updateTime": {
"type": "date"
}
}
}
}
}
创建索引时指定 mapping 和 settings
PUT movie
{
"mappings" : {
"properties" : {
"name" : {
"type" : "keyword"
}
}
},
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 2
}
}
}
获取索引 mapping
GET hyperion-novel
上面这种方式会有个警告:
Deprecation: [types removal] The parameter include_type_name should be explicitly specified in get indices requests to prepare for 7.0. In 7.0 include_type_name will default to ‘false’, which means responses will omit the type name in mapping definitions.
在后面加上 ?include_type_name=true 可以避免这个警告。
GET /hyperion-novel/?include_type_name=true
下面这种写法也是同样的功能:
GET /hyperion-novel/_mapping/novel?include_type_name=true
禁止自动创建索引
默认查询时会自动创建索引,可以通过如下命令禁用。
PUT _cluster/settings
{
"persistent": {
"action.auto_create_index": "false"
}
}
2021-08-17 追记
禁用查询时自动创建索引后,logstash 由于无法自动创建索引,导致向 elasticsearch 中写入数据时会失败。