弹性查询的性能 [英] Performance of elastic queries

查看:115
本文介绍了弹性查询的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此查询每次执行时都需要200多个ms:

This query takes 200+ ms every time it is executed:

{
  "filter": {
    "term": {
      "id": "123456",
      "_cache": true
    }
  }
}

但是,每次在第一次查询后,每次执行2-3 ms:

but this one only takes 2-3 ms every time it is executed after the first query:

{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "term": {
          "id": "123456"
        }
      }
    }
  }
}

注意两者中相同的ID值查询。看起来第二个查询使用第一个查询的缓存结果。但是为什么第一个查询不能使用缓存的结果本身?从第一个查询中删除_ cache:true 不会更改任何内容。

Note the same ID values in both queries. Looks like the second query uses cached results from the first query. But why the first query cannot use the cached results itself? Removing "_cache" : true from the first query doesn't change anything.

当我执行第二个查询一些其他的ID,需要〜40 ms第一次执行它,每次后2-3 ms。所以第二个查询不仅工作得更快,而且缓存结果,并使用缓存进行后续调用。

And when I execute the second query with some other ID, it takes ~ 40 ms to execute it for the first time and 2-3 ms every time after that. So the second query not only works faster but it also caches the results and uses the cache for subsequent calls.

有没有解释所有这些?

推荐答案

第一个请求中的顶层过滤器元素在Elasticsearch中有非常特殊的功能。它用于过滤搜索结果而不影响方面。为了避免干扰小平面,该过滤器在收集结果期间应用,而不是在搜索期间应用,这导致其性能降低。使用顶级过滤器没有方面意义非常小,因为过滤 constant_score 查询通常提供更好的性能。如果过滤查询与 match_all 的详细程度困扰您,则可以将您的第二个请求重写为等价的 constant_score 查询:

The top-level filter element in the first request has very special function in Elasticsearch. It's used to filter search result without affecting facets. In order to avoid interfering with facets, this filter is applied during collection of results and not during searching, which causes its slow performance. Using top-level filter without facets makes very little sense because filtered and constant_score queries typically provide much better performance. If verbosity of filtered query with match_all bothers you, you can rewrite your second request into equivalent constant_score query:

{
  "query": {
    "constant_score": {
      "filter": {
        "term": {
          "id": "123456"
        }
      }
    }
  }
}

这篇关于弹性查询的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆