elasticsearch之explain的使用

本文探讨了如何使用Elasticsearch的explain功能来理解查询得分的计算方式,并展示了如何将搜索结果从JSON格式转换为YAML格式进行展示。此外,还深入分析了文档匹配失败的具体原因,帮助读者更深入地理解Elasticsearch的查询机制。

explain查看怎么计算得分的,format将json格式结果转为yaml展示

POST tlsmz/_search?format=yaml
{
  "explain": true, 
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "fz.keyword": {
              "value": "南昌西"
            }
          }
        },
        {
          "bool": {
            "should": [
              {
                "match": {
                  "dz": "长沙"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

通过/index/_explain/id 可以看到我们的文档是否被匹配,为什么匹配/不匹配。详细的原因

GET tlsmz/_explain/A53AC90D8F3941B8E055000000000001
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "fz.keyword": {
              "value": "南昌西"
            }
          }
        },
        {
          "bool": {
            "should": [
              {
                "match": {
                  "dz": "长沙"
                }
              }
            ]
          }
        }
      ]
    }
  }
}
{
  "_index" : "tlsmz",
  "_type" : "_doc",
  "_id" : "A53AC90D8F3941B8E055000000000001",
  "matched" : false,
  "explanation" : {
    "value" : 0.0,
    "description" : "Failure to meet condition(s) of required/prohibited clause(s)",
    "details" : [
      {
        "value" : 0.0,
        "description" : "no match on required clause (fz.keyword:南昌西)",
        "details" : [
          {
            "value" : 0.0,
            "description" : "no matching term",
            "details" : [ ]
          }
        ]
      },
      {
        "value" : 0.0,
        "description" : "no match on required clause (dz:长沙)",
        "details" : [
          {
            "value" : 0.0,
            "description" : "no matching term",
            "details" : [ ]
          }
        ]
      }
    ]
  }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值