2015-05-15 138 views
3

我有一個非常複雜的搜索,其中我基本上執行大量搜索與許多實體組中的至少一個實體相匹配的文章。如何在ElasticSearch的bool查詢中獲取基礎匹配查詢的分數?

我注意到,隨着我添加更多的實體,分數急劇變化,因爲我的should子句大小增加。

這裏是我的查詢示例2個實體:

{ 
    "size": 50, 
    "track_scores": true, 
    "min_score": 0.05, 
    "sort": [ 
    { 
     "timestamp": { 
     "order": "desc" 
     } 
    } 
    ], 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "bool": { 
      "should": [ 
       { 
       "function_score": { 
        "functions": [ 
        { 
         "boost_factor": 1000000 
        } 
        ], 
        "query": { 
        "terms": { 
         "relatedProfiles": [ 
         "SomethingElse/124026966662", 
         "SomeLocation/707765" 
         ] 
        } 
        }, 
        "boost_mode": "replace" 
       } 
       }, 
       { 
       "bool": { 
        "should": [ 
        { 
         "multi_match": { 
         "type": "phrase", 
         "query": "Generic Systems", 
         "operator": "and", 
         "fields": [ 
          "content.title", 
          "content.description" 
         ] 
         } 
        }, 
        { 
         "multi_match": { 
         "type": "phrase", 
         "query": "Generic Systems, Inc.", 
         "operator": "and", 
         "fields": [ 
          "content.title", 
          "content.description" 
         ] 
         } 
        } 
        ], 
        "minimum_should_match": "1" 
       } 
       } 
      ], 
      "minimum_should_match": "1", 
      "_name": "0e7da739-1d18-448b-caa2-5c615a59d108" 
      } 
     }, 
     { 
      "bool": { 
      "should": [ 
       { 
       "function_score": { 
        "functions": [ 
        { 
         "boost_factor": 1000000 
        } 
        ], 
        "query": { 
        "terms": { 
         "relatedProfiles": [ 
         "SomeLocation/162479", 
         "SomethingElse/32b95cc3-a363-47c3-2ac1-86fdb3b7d108" 
         ] 
        } 
        }, 
        "boost_mode": "replace" 
       } 
       }, 
       { 
       "bool": { 
        "should": [ 
        { 
         "multi_match": { 
         "type": "phrase", 
         "query": "SomeBusiness Computer Inc", 
         "operator": "and", 
         "fields": [ 
          "content.title", 
          "content.description" 
         ] 
         } 
        }, 
        { 
         "multi_match": { 
         "type": "phrase", 
         "query": "SomeBusiness, Inc", 
         "operator": "and", 
         "fields": [ 
          "content.title", 
          "content.description" 
         ] 
         } 
        } 
        ], 
        "minimum_should_match": "1" 
       } 
       } 
      ], 
      "minimum_should_match": "1", 
      "_name": "00cc4b36-ce6b-4816-e61e-b7124344d108" 
      } 
     } 
     ], 
     "minimum_should_match": "1" 
    } 
    }, 
    "filter": { 
    "bool": { 
     "must": [ 
     { 
      "bool": { 
      "should": [ 
       { 
       "bool": { 
        "must": [ 
        { 
         "term": { 
         "type": "News" 
         } 
        }, 
        { 
         "terms": { 
         "language": [ 
          "eng" 
         ] 
         } 
        } 
        ] 
       } 
       }, 
       { 
       "terms": { 
        "type": [ 
        "Social", 
        "Job", 
        "Unknown" 
        ] 
       } 
       } 
      ] 
      } 
     }, 
     { 
      "range": { 
      "timestamp": { 
       "lt": "2015-05-13T09:25:40.605", 
       "gt": "2013-05-13T09:25:40.605" 
      } 
      } 
     } 
     ] 
    } 
    } 
} 

我怎樣才能獲得潛在的比賽是得分?或者,至少是名稱查詢下面的部分的分數?

回答

0

您可以使用explain API。在提供查詢時,它會爲您提供有關每個文檔匹配的大量信息,以便推導出該分數。它是調試分數的完美工具。

+0

不幸的是,我不想調試分數,而是在查詢中不存在一個實體影響其他實體的分數。 –

+0

也許https://www.elastic.co/webinars/elasticsearch-query-dsl有一些見解;後來在視頻中他談到了* Dis Max Query:https://www.elastic.co/guide/en/elasticsearch/reference/1.5/query-dsl-dis-max-query.html「我們希望主要得分是與最高提升相關的分數,而不是場分數的總和(如布爾查詢所給出的)。「或者,也許是」恆定分數查詢「:https://www.elastic.co/guide/en/ elasticsearch/reference/1.5/query-dsl-constant-score-query.html但TBH給你的描述我不確定你真正的目標是什麼 – mark

+0

@mark,你可以做出答案,而不是像我這樣評論可以接受它嗎?您的Dis Max查詢忠告已被發現! –

相關問題