Elasticsearch 论坛实战-基于tie_breaker参数优化dis_max搜索效果
Elasticsearch實戰
準備數據
PUT /forum/post/_bulk {"index":{"_id":1}} {"title":"java php", "content":"forum open MIjMReACTGaN564AnCZuHg"} {"index":{"_id":2}} {"title":"elasticsearch java apm-agent-configuration KvkaTyKFT-2zocQNC9j5nA", "content":"kibana post open MIjMReACTGaN564AnCZuHg 4508327 NfcOxURmuyoBIxJBSbvw MIjMReACTGaN564AnCZuHg"} {"index":{"_id":3}} {"title":"elasticsearch hadoop", "content":"kibana green open"}繼續上一課時dis_max查詢上面的數據
GET /forum/post/_search {"query": {"dis_max": {"queries": [{"match": {"title": "java kibana"}},{"match": {"content": "java kibana"}}]}} }#! Deprecation: [types removal] Specifying types in search requests is deprecated.
{
? "took" : 0,
? "timed_out" : false,
? "_shards" : {
? ? "total" : 1,
? ? "successful" : 1,
? ? "skipped" : 0,
? ? "failed" : 0
? },
? "hits" : {
? ? "total" : {
? ? ? "value" : 3,
? ? ? "relation" : "eq"
? ? },
? ? "max_score" : 0.5773649,
? ? "hits" : [
? ? ? {
? ? ? ? "_index" : "forum",
? ? ? ? "_type" : "post",
? ? ? ? "_id" : "1",
? ? ? ? "_score" : 0.5773649,
? ? ? ? "_source" : {
? ? ? ? ? "title" : "java php",
? ? ? ? ? "content" : "forum open MIjMReACTGaN564AnCZuHg"
? ? ? ? }
? ? ? },
? ? ? {
? ? ? ? "_index" : "forum",
? ? ? ? "_type" : "post",
? ? ? ? "_id" : "3",
? ? ? ? "_score" : 0.5376842,
? ? ? ? "_source" : {
? ? ? ? ? "title" : "elasticsearch hadoop",
? ? ? ? ? "content" : "kibana green open"
? ? ? ? }
? ? ? },
? ? ? {
? ? ? ? "_index" : "forum",
? ? ? ? "_type" : "post",
? ? ? ? "_id" : "2",
? ? ? ? "_score" : 0.3754778,
? ? ? ? "_source" : {
? ? ? ? ? "title" : "elasticsearch java apm-agent-configuration KvkaTyKFT-2zocQNC9j5nA",
? ? ? ? ? "content" : "kibana post open MIjMReACTGaN564AnCZuHg ?4508327 NfcOxURmuyoBIxJBSbvw MIjMReACTGaN564AnCZuHg"
? ? ? ? }
? ? ? }
? ? ]
? }
}
?
?
我們不難發現文檔1和3分別是title和content命中了,而文檔2兩項都命中了卻排在了最后~為什么呢?
學習過前面課時的同學應該不難發現,文檔2的長度都特別長,所以單項的title或者content得分都會低,而dis_max只取最高分,所以出現上面的結果。
?
tie_breaker
將其他query的分乘以tie_breaker然后再綜合計算,也就是說不但看最高分,其他的也會考慮
GET /forum/post/_search {"query": {"dis_max": {"queries": [{"match": {"title": "java kibana"}},{"match": {"content": "java kibana"}}],"tie_breaker": 0.7}} }#! Deprecation: [types removal] Specifying types in search requests is deprecated.
{
? "took" : 0,
? "timed_out" : false,
? "_shards" : {
? ? "total" : 1,
? ? "successful" : 1,
? ? "skipped" : 0,
? ? "failed" : 0
? },
? "hits" : {
? ? "total" : {
? ? ? "value" : 3,
? ? ? "relation" : "eq"
? ? },
? ? "max_score" : 0.61529297,
? ? "hits" : [
? ? ? {
? ? ? ? "_index" : "forum",
? ? ? ? "_type" : "post",
? ? ? ? "_id" : "2",
? ? ? ? "_score" : 0.61529297,
? ? ? ? "_source" : {
? ? ? ? ? "title" : "elasticsearch java apm-agent-configuration KvkaTyKFT-2zocQNC9j5nA",
? ? ? ? ? "content" : "kibana post open MIjMReACTGaN564AnCZuHg ?4508327 NfcOxURmuyoBIxJBSbvw MIjMReACTGaN564AnCZuHg"
? ? ? ? }
? ? ? },
? ? ? {
? ? ? ? "_index" : "forum",
? ? ? ? "_type" : "post",
? ? ? ? "_id" : "1",
? ? ? ? "_score" : 0.5773649,
? ? ? ? "_source" : {
? ? ? ? ? "title" : "java php",
? ? ? ? ? "content" : "forum open MIjMReACTGaN564AnCZuHg"
? ? ? ? }
? ? ? },
? ? ? {
? ? ? ? "_index" : "forum",
? ? ? ? "_type" : "post",
? ? ? ? "_id" : "3",
? ? ? ? "_score" : 0.5376842,
? ? ? ? "_source" : {
? ? ? ? ? "title" : "elasticsearch hadoop",
? ? ? ? ? "content" : "kibana green open"
? ? ? ? }
? ? ? }
? ? ]
? }
}
?
歡迎訪問我的個人博客:小馬博客
項目源碼關注公眾號《JAVA拾貝》
總結
以上是生活随笔為你收集整理的Elasticsearch 论坛实战-基于tie_breaker参数优化dis_max搜索效果的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 也许履历表可以这样填
- 下一篇: IPCamera