ElasticSearch 手记
安装后要修改的配置
path.data 和 path.logs (默认在安装目录)
cluster.name (不同的环境不要使用同一个集群的名称,节点容易假如错误的集群)
node.name
bootstrap.memory_lock
network.host
discovery.zen.ping.unicast.hosts
discovery.zen.minimum_master_nodes
参考:http://cwiki.apachecn.org/pages/viewpage.action?pageId=4882617
对所有索引设置
PUT /_all/_settings
对集群设置
cluster settings
PUT /_cluster/settings
{
# 永久变更, 它会覆盖掉静态配置文件里的选项
"persistent" : {
"discovery.zen.minimum_master_nodes" : 2
},
# 临时修改 , 重启后清除
"transient" : {
"indices.store.throttle.max_bytes_per_sec" : "50mb"
}
}
索引写入速度优化设置
参考:http://www.mamicode.com/info-detail-1570228.html
分片设置,副本分片配置可以随时调整
"number_of_shards": 5,
"number_of_replicas": 0, // 复制分片设为0,提高写入性能
归并策略(todo,没明白怎么调参数优化)
"index.merge.policy.max_merged_segment": "1gb",
"index.merge.policy.segments_per_tier": "24",
降低数据安全性
"index.translog.durability": "async",
优化elasticsearch的flush操作
"index.translog.flush_threshold_size": "2000mb",
"index.translog.flush_threshold_period": 每隔多长时间执行一次flush(默认30m)
"index.translog.flush_threshold_ops": 当事务日志累积到多少条数据后flush一次
降低实时检索,默认值1s
"index.translog.sync_interval": "120s" // 如果不需要特别强的实时性,可将刷新时间设置大一点
设置索引模板
{
"template":"product_stat_*",
"settings":{
"number_of_shards": 5,
"number_of_replicas": 0,
"index.translog.durability": "async",
"index.translog.flush_threshold_size": "2000mb",
"index.translog.sync_interval": "120s"
},
"mappings":{
"_default_":{
"_all":{
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"properties":{
"product_id": {
"type":"keyword"
},
"shop_code": {
"type": "keyword"
},
"day": {
"type": "keyword"
},
"site_id":{
"type":"keyword"
}
}
}
}
}