2015-05-15 168 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查询忠告已被发现! –

相关问题