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"
我的索引需求如下:
- 需要索引的字段有很多个,远远大于默认的1000个
- 需要动态创建字段索引,dynamic默认为true
- 禁止字符串自动转换,关闭时间和数字转换
创建索引
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}'
只能通过重建索引修改索引字段mapping
ES不能修改字段类型是个很蛋疼的事情,只能重新新建一个索引
- 业务代码操作的时候使用索引别名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"}}]}'
- 先创建另外一个索引2:myindex2
- 根据索引1的mapping修改好字段类型,提前建好索引2的mapping
- 执行_reindex,将索引1的数据全部迁移到索引2中
POST _reindex
{
"source":{"index":"myindex"},
"dest":{"index":"myindex2"}
}
-
需要禁止自动创建索引, 如果不禁止的话在切换别名过程中就会自动创建一个和索引别名相同的索引
PUT _cluster/settings
{
“persistent”: {
“action.auto_create_index”: “false”
}
} -
删除索引1的别名,给索引2创建别名myindex_business
POST /_aliases
{
"actions": [
{
"remove": {
"index": "myindex1",
"alias": "myindex_business"
}
},
{
"add": {
"index": "myindex2",
"alias": "myindex_business"
}
}
]
}
- 删除索引1
curl -XDELETE -u elastic:changeme http://localhost:9200/myindex
6.在导入大量数据或者需要批量修改大量数据时,将index.refresh_interval设置为-1并将index.number_of_replicas设置为0来禁用刷新, 导入完成以后再修改回去
PUT /my_index/_settings
{ “refresh_interval”: -1 }
PUT /my_index/_settings
{ “refresh_interval”: “1s” }