es創建索引及別名更新mapping方法 elasticsearch [nested] nested object under path [XXX] is not of nested type


[nested] nested object under path [XXX] is not of nested type這是因為在創建索引時沒有指定類型為數組,這就是一個大坑,ES官方說可以不用指定數字組類型,結果不指定的聚合結果還不一樣!!!

由於Elasticsearch底層使用了lucene的原因,不支持對mapping的修改,可使用索引重建的方式,升級版本的思路來做別名映射處理。
1.創建索引 創建一個索引,這個索引的名稱最好帶上版本號,比如my_index_v1,my_index_v2等。
my_index_v1 PUT
{
"settings": {
"index.mapping.total_fields.limit": 2000,
"number_of_shards": 5,
"number_of_replicas": 1
}
"mappings": {
"_doc": {
...
}
}

2.索引復制,使用reindex api將舊索引數據導入新索引
_reindex POST
{
"source": {
"index": "my_index",
"type": "_doc"
},

"dest": {
"index": "my_index_v1",
"type": "_doc"

}
}

3.在視圖確認已經創建且復制成功,然后刪除原來的索引
my_index  DELETE

4.創建同之前的索引的相同名稱的別名,不刪除索引而創建同名的別名會報錯“an index exists with the same name as the alias”
/_aliases PUT
{
"actions": [
{ "add": {
"alias": "my_index",
"index": "my_index_v1"
}}
]
}
如果需要刪除別名
/_aliases PUT
{
"actions": [
{ "remove": {
"alias": "my_index",
"index": "my_index_v1"
}}
]
}
無縫切換
{
"actions": [
{ "remove": {
"alias": "my_index",
"index": "my_index_v1"
}},
{ "add": {
"alias": "my_index",
"index": "my_index_v2"
}}
]
}

5.查看別名
_alias GET

查看別名
http://IP地址:9201/_cat/aliases


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM