我在Elasticsearch中有一个复杂的查询。很慢我想优化它。
但是我不知道该如何工作。
如何解释查询,就像Sql解释一样。

我看到elastichsearch _valite / query?explain。它可以解释分数。
但我需要查看详细的执行计划。

{
  "post_filter": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "base.sysCode": "2801"
                }
              },
              {
                "term": {
                  "base.status": [
                    12,
                    0
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  },
  "fields": [
    "base.sysCode",
    "base.orderNo"
  ]
}

结果
{
"valid": true,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"explanations": [
{
"index": "odi_bus_betad_2013",
"valid": true,
"explanation": "ConstantScore(*:*)"
}
]
}

最佳答案

解释API

计算查询和特定文档的分数说明。无论文档是匹配还是不匹配特定查询,这都可以提供有用的反馈。

添加"explain": true

GET /_search
{
    "explain": true,
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

Explain Documentation

个人资料API

提供有关搜索请求中各个组件执行的详细时序信息。它使用户可以洞悉搜索请求是如何在低级执行的,从而使用户可以理解为什么某些请求很慢的原因,并采取措施来改进它们。

添加"profile": true
GET /_search
{
  "profile": true,
  "query" : {
    "match" : { "user" : "kimchy" }
  }
}

Profile Documentation

10-06 12:56
查看更多