Elasticsearch优化

背景:近期使用ES摸索到一些优化方式

1:API使用,不需要打分推荐使用filter

 

Query context 查询上下文 这种语句在执行时既要计算文档是否匹配,还要计算文档相对于其他文档的匹配度有多高,匹配度越高,_score 分数就越高

  • Filter context 过滤上下文 过滤上下文中的语句在执行时只关心文档是否和查询匹配,不会计算匹配度,也就是得分
  • query 参数表示整个语句是处于 query context 中
  • bool 和 match 语句被用在 query context 中,也就是说它们会计算每个文档的匹配度(_score)
  • filter 参数则表示这个子查询处于 filter context 中
  • filter 语句中的 term 和 range 语句用在 filter context 中,它们只起到过滤的作用,并不会计算文档的得分。

filter示例:

GET test_index/_search
{
	"from": 0,
	"size": 50,
	"query": {
		"bool": {
			"filter": [{
				"terms": {
					"name": ["zhangsan"],
					"boost": 1.0
				}
			},{
				"terms": {
					"id": [ "0"],
					"boost": 1.0
				}
			}, {
				"terms": {
					"date": [20200413],
					"boost": 1.0
				}
			}],
			"adjust_pure_negative": true,
			"boost": 1.0
		}
	},
	"version": true
}

 2限制segment合并

 3:查看缓存命中情况(适用filter)

       GET _stats/query_cache

   "my_index" : {
      "uuid" : "xAm5VgvfT2qZBiMnmQZiYg",
      "primaries" : {
        "query_cache" : {
          "memory_size_in_bytes" : 0,
          "total_count" : 0,
          "hit_count" : 0,
          "miss_count" : 0,
          "cache_size" : 0,
          "cache_count" : 0,
          "evictions" : 0
        }
      },
      "total" : {
        "query_cache" : {
          "memory_size_in_bytes" : 0,
          "total_count" : 0,
          "hit_count" : 0,
          "miss_count" : 0,
          "cache_size" : 0,
          "cache_count" : 0,
          "evictions" : 0
        }
      }
    }

4:查看缓存命中情况(适用request)

       GET _stats/request_cache

       API searchRequest.requestCache(true);

      "total" : {
        "request_cache" : {
          "memory_size_in_bytes" : 5594,
          "evictions" : 0,
          "hit_count" : 5201,
          "miss_count" : 4
        }
      }

5:性能分析

    "profile": true ,"explain": true,     

GET test_index/_search
{
    "profile": true ,
    "explain": true,
	"from": 0,
	"size": 50,
	"query": {
		"bool": {
			"filter": [{
				"terms": {
					"name": ["zhangsan"],
					"boost": 1.0
				}
			},{
				"terms": {
					"id": [ "0"],
					"boost": 1.0
				}
			}, {
				"terms": {
					"date": [20200413],
					"boost": 1.0
				}
			}],
			"adjust_pure_negative": true,
			"boost": 1.0
		}
	},
	"version": true
}

6:常用命令(kibana)

GET _settings



GET _cluster/settings


PUT /_cluster/settings
{
  "persistent": {
    "xpack.monitoring.history.duration":"1d",
    "xpack.monitoring.collection.interval":"10s"
  }
}


GET _cat/thread_pool

GET ad_index/_stats

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值