简体   繁体   English

Elasticsearch:如何获得总得分作为提升点的总和?

[英]Elasticsearch: How to get total score as sum of boost points?

I am sending query like this:(using query { all }) 我正在发送这样的查询:(使用查询{all})

{
  "query": {
    "custom_filters_score": {
      "query": {
        "match_all": {}
      },
      "filters": [
        {
          "filter": {
            "range": {
              "last_contact_at": {
                "gte": "2013-06-21T12:02:25Z"
              }
            }
          },
          "boost": 1
        },
        {
          "filter": {
            "range": {
              "available_at": {
                "gte": "2013-06-28"
              }
            }
          },
          "boost": 2
        },
        {
          "filter": {
            "term": {
              "company_type": "intern"
            }
          },
          "boost": 10
        },
        {
          "filter": {
            "range": {
              "friends_count": {
                "from": 1
              }
            }
          },
          "boost": 3
        },
        {
          "filter": {
            "term": {
              "blacklisted": true
            }
          },
          "boost": -100
        },
        {
          "filter": {
            "term": {
              "focuses": "ruby php"
            }
          },
          "boost": 5
        },
        {
          "filter": {
            "term": {
              "tags": "ruby php"
            }
          },
          "boost": 4
        }
      ],
      "score_mode": "total"
    }
  }
}

and I get following response with max_score: 16 which is sum of my boost points. 我得到以下max_score响应:16这是我的提升点的总和。

Response 响应

{
   "took": 3,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 10,
      "max_score": 16,
...

And when I am sending the same custom_filters_score but with query { string term } 当我发送相同的custom_filters_score但查询{字符串term}时

{
  "query": {
    "custom_filters_score": {
      "query": {
        "query_string": {
          "query": "ruby php"
        }
      },
      "filters": [
        {
          "filter": {
            "range": {
              "last_contact_at": {
                "gte": "2013-06-21T12:03:46Z"
              }
            }
          },
          "boost": 1
        },
        {
          "filter": {
            "range": {
              "available_at": {
                "gte": "2013-06-28"
              }
            }
          },
          "boost": 2
        },
        {
          "filter": {
            "term": {
              "company_type": "intern"
            }
          },
          "boost": 10
        },
        {
          "filter": {
            "range": {
              "friends_count": {
                "from": 1
              }
            }
          },
          "boost": 3
        },
        {
          "filter": {
            "term": {
              "blacklisted": true
            }
          },
          "boost": -100
        },
        {
          "filter": {
            "term": {
              "focuses": "ruby php"
            }
          },
          "boost": 5
        },
        {
          "filter": {
            "term": {
              "tags": "ruby php"
            }
          },
          "boost": 4
        }
      ],
      "score_mode": "total"
    }
  }
}

and I get following response with max_score: 8.990471 我得到max_score以下响应:8.990471

Response 响应

{
   "took": 4,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 6,
      "max_score": 8.990471,
...

How to achieve max_score as sum of my boost points and also show only results which contains term ? 如何获得max_score作为我的提升点的总和,并且仅显示包含term的结果?

SearchService : https://gist.github.com/8f13ce2be820d9ef1959 SearchServicehttps : //gist.github.com/8f13ce2be820d9ef1959

From the es docs it looks like: es文档来看,它看起来像:

  1. The query is run and a set of hits generated 运行查询并生成一组匹配
  2. The filters are run on the set of hits to give them a score. 过滤器将在匹配组上运行,以为其打分。

It looks like the document with the score of 16 (from the match_all query) doesnt match the "query_string":{"query":"ruby php"} in your second search, that is why the max_score is less. 看起来分数为16(来自match_all查询)的文档在您的第二次搜索中与"query_string":{"query":"ruby php"} match_all "query_string":{"query":"ruby php"}不匹配,这就是max_score较小的原因。

Also you say that 16, is the sum of all your boost points, but when I add up the score form the filters I get 25, or -75 if you include the blacklist... 您也说16是所有提升点的总和,但是当我将分数加到过滤器中时,我得到25,如果包括黑名单,则得到-75。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM