ES学习记录9.3——请求体搜索(得分说明Explain、版本、索引激励、不及格文档、命名查询、内部命中)

本文介绍了Elasticsearch的搜索增强特性,包括如何开启评分说明(Explain)、获取文档版本(Version)、设置索引激励(Index Boost)、忽略得分低的文档、命名查询(Named Query)以及内部命中,帮助读者深入理解这些高级搜索功能的工作原理和应用场景。
摘要由CSDN通过智能技术生成

1. 开启打分说明(Explain)

 在搜索时,可以开启评分说明"explain": true,请求响应中每个命中的文档会额外返回一个得分说明字段_explanation,如:

curl -X GET "localhost:9200/_search" -H 'Content-Type: application/json' -d'
{
   
    "explain": true,
    "query" : {
   
        "term" : {
    "content" : "中国" }
    }
}
'

返回的结果为:

{
   
    "took": 1,
    "timed_out": false,
    "_shards": {
   
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
   
        "total": 2,
        "max_score": 1.111892,
        "hits": [
            {
   
                "_shard": "[index][2]",
                "_node": "bKeGC-Q-SXuyyGlcarDrMg",
                "_index": "index",
                "_type": "fulltext",
                "_id": "4",
                "_score": 1.111892,
                "_source": {
   
                    "content": "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
                },
                // 返回得分说明
                "_explanation": {
   
                    "value": 1.111892,
                    "description": "weight(content:中国 in 0) [PerFieldSimilarity], result of:",
                    "details": [
                        {
   
                            "value": 1.111892,
                            "description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
                            "details": [
                                {
   
                                    "value": 0.98082924,
                                    "description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
                                    "details": [
                                        {
   
                                            "value": 1,
                                            "description": "docFreq",
                                            "details": []
                                        },
                                        {
   
                                            "value": 3,
                                            "description": "docCount",
                                            "details": []
                                        }
                                    ]
                                },
                                {
   
                                    "value": 1.1336244,
                                    "description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
                                    "details": [
                                        {
   
                                            "value": 1,
                                            "description": "termFreq=1.0",
                                            "details": []
                                        },
                                        {
   
                                            "value": 1.2,
                                            "description": "parameter k1",
                                            "details": []
                                        },
                                        {
   
                                            "value": 0.75,
                                            "description": "parameter b",
                                            "details": []
                                        },
                                        {
   
                                            "value": 19.666666,
                                            "description": "avgFieldLength",
                                            "details": []
                                        },
                                        {
   
                                            "value": 14,
                                            "description": "fieldLength",
                                            "details": []
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            },
            // ...
        ]
    }
}

2. 开启版本说明(Version)

 就是在搜索时,配置"version": true,指定命中结果中也返回文档版本号,如下:

curl -X GET "localhost:9200/_search" -H 'Content-Type: application/json' -d'
{
   
	"version": true,
	"query": {
   
		"term": {
   "content": "中国"}
	}
}
'

返回的结果会带有命中结果的版本号version,如下:

{
   
    "took": 0,
    "timed_out": false,
    
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值