ElasticSearch設置和索引重建

我的索引需求如下:

  1. 需要索引的字段有很多個,遠遠大於默認的1000個
  2. 需要動態創建字段索引,dynamic默認爲true
  3. 禁止字符串自動轉換,關閉時間和數字轉換

創建索引

PUT myindex
{
    "settings": {
        "number_of_shards": 5,
        "number_of_replicas": 2,
        "index.mapping.total_fields.limit":200000,
        "index.max_result_window":100000
    }
}
curl -XPUT http://localhost:9200/myindex/_settings -d '{"index.mapping.total_fields.limit":200000,"index.max_result_window":5000000}'

關閉時間和數字自動轉換,時間字符串仍然保存爲字符串

PUT myindex
{
  "mappings": {
    "date_detection": false,
    "numeric_detection": false
  }
}
curl -XPUT http://localhost:9200/myindex/test/_mapping -d '{"date_detection": false,"numeric_detection": false}'

修改索引字段

ES不能修改字段類型是個很蛋疼的事情,只能重新新建一個索引

  1. 業務代碼操作的時候使用索引別名myindex_business
POST /_aliases
{
 "actions": [
   {
     "add": {
       "index": "myindex",
       "alias": "myindex_business"
     }
   }
 ]
}
curl -XPOST http://localhost:9200/_aliases -d '{"actions":[{"add":{"index":"myindex","alias":"myindex_business"}},{"add":{"index":"myindex2","alias":"myindex_business2"}}]}'
  1. 先創建另外一個索引2:myindex2
  2. 根據索引1的mapping修改好字段類型,提前建好索引2的mapping
  3. 執行_reindex,將索引1的數據全部遷移到索引2中
POST _reindex
{
"source":{"index":"myindex"},
"dest":{"index":"myindex2"}
}
  1. 刪除索引1的別名,給索引2創建別名myindex_business
POST /_aliases
{
 "actions": [
   {
     "add": {
       "index": "myindex2",
       "alias": "myindex_business"
     }
   }
 ]
}
  1. 刪除索引1
  curl -XDELETE -u elastic:changeme http://localhost:9200/myindex
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章