1. 索引模板创建索引
可以通过kibana工具进行创建索引模板文章来源:https://www.toymoban.com/news/detail-528291.html
也可以自定义语句,如创建poi索引模板文章来源地址https://www.toymoban.com/news/detail-528291.html
POST _index_template/poi
{
"index_patterns": ["poi*"],
"template" : {
"settings" : {
"index" : {
"number_of_shards" : "1",
"number_of_replicas" : "1"
}
},
"mappings" : {
"dynamic": "strict", // 严格模式,不允许动态创建字段
"properties" : {
"city" : {
"type" : "keyword"
},
"region" : {
"type" : "keyword"
},
"name" : {
"type" : "text"
},
"location" : {
"type" : "geo_point" // 地址坐标点类型,可以进行范围搜索
}
}
}
}
}
# 查看创建的索引
GET _index_template/poi
# 创建索引
PUT poi
# 查看索引
GET poi
2. 索引新增字段及重建
# 索引poi新增创建时间字段
PUT poi/_mapping
{
"properties": {
"c_date": {
"type": "date"
}
}
}
# 当想对name进行中文分词时,需要重建索引,然后修改模板,删除旧索引,在重建回来,如下步骤
POST _reindex
{
"source": {
"index": "poi"
},
"dest": {
"index": "poi_bak"
}
}
POST _index_template/poi
{
"index_patterns": ["poi*"],
"template" : {
"settings" : {
"index" : {
"number_of_shards" : "1",
"number_of_replicas" : "1"
}
},
"mappings" : {
"dynamic": "strict",
"properties" : {
"city" : {
"type" : "keyword"
},
"region" : {
"type" : "keyword"
},
"name" : {
"type" : "text",
"analyzer": "ik_smart" // 新增分词
},
"location" : {
"type" : "geo_point"
}
}
}
}
}
DELETE poi
PUT POI
POST _reindex
{
"source": {
"index": "poi_bak"
},
"dest": {
"index": "poi"
}
}
// 如果想修改字段名,可在重建时进行修改
POST _reindex?wait_for_completion=false
{
"source": {
"index": "poi_bak"
},
"dest": {
"index": "poi"
},
"script": {
"source": "ctx._source.paiMaiType=ctx._source.remove(\"zcType\")"
}
}
DELETE poi_bak
3. 远程索引同步
# 远程索引同步至本地,conflicts=proceed遇到错误忽略继续执行
POST _reindex?wait_for_completion=false
{
"source": {
"remote": {
"host": "http://192.168.0.XX:9200",
"socket_timeout": "30s",
"connect_timeout": "30s",
"username": "xxxx",
"password": "xxxx"
},
"index": "poi",
"size": 1000,
"query": {
"match_all": {}
}
},
"dest": {
"index": "poi"
}
}
到了这里,关于8.ElasticSearch系列之索引模板与索引的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!