ElasticSearch设置和索引重建

in查询条件大于默认的1024个
在elasticsearch.yml中新增一条配置
vi /data/server/elasticsearch/config/elasticsearch.yml
indices.query.bool.max_clause_count: 10240
修改完以后重启es:

kill -9 $(ps -ef | grep 'elasticsearch' | grep -v grep | awk '{print $2}')
su - elsearch -c "/data/server/elasticsearch/bin/elasticsearch -d"

我的索引需求如下:

  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

你可能感兴趣的:(服务器)