elasticsearch查询性能优化

  1. 评分查询转为不评分查询
    例子1:通过将 range 查询移到 filter 语句中,我们将它转成不评分的查询,将不再影响文档的相关性排名。由于它现在是一个不评分的查询,可以使用各种对 filter 查询有效的优化手段来提升性能。所有查询都可以借鉴这种方式。将查询移到 bool 查询的 filter 语句中,这样它就自动的转成一个不评分的 filter 了。
        {
            "bool": {
                "must":     { "match": { "title": "how to make millions" }},
                "must_not": { "match": { "tag":   "spam" }},
                "should": [
                    { "match": { "tag": "starred" }}
                ],
                "filter": {
                  "range": { "date": { "gte": "2014-01-01" }} 
                }
            }
        }
    
    如果你需要通过多个不同的标准来过滤你的文档,bool 查询本身也可以被用做不评分的查询。简单地将它放置到 filter 语句中并在内部构建布尔逻辑:
        {
            "bool": {
                "must":     { "match": { "title": "how to make millions" }},
                "must_not": { "match": { "tag":   "spam" }},
                "should": [
                    { "match": { "tag": "starred" }}
                ],
                "filter": {
                  "bool": { 
                      "must": [
                          { "range": { "date": { "gte": "2014-01-01" }}},
                          { "range": { "price": { "lte": 29.99 }}}
                      ],
                      "must_not": [
                          { "term": { "category": "ebooks" }}
                      ]
                  }
                }
            }
        }
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。