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

时间:2013-06-28 12:15:38

标签: ruby-on-rails ruby ruby-on-rails-3 elasticsearch tire

我发送的查询如下:(使用查询{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"
    }
  }
}

我得到跟随max_score的响应:16这是我的加速点的总和。

响应

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

当我发送相同的custom_filters_score但查询{string 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"
    }
  }
}

我用max_score得到以下回复:8.990471

响应

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

如何将max_score作为我的提升点的总和,并且只显示包含术语的结果?

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

1 个答案:

答案 0 :(得分:0)

es docs看起来像:

  1. 运行查询并生成一组匹配
  2. 过滤器在命中集上运行,以给予分数。
  3. 看起来得分为16的文档(来自match_all查询)与第二次搜索中的"query_string":{"query":"ruby php"}不匹配,这就是max_score较少的原因。

    另外你说16,是你所有提升点的总和,但是当我将得分加起来时我得到25分,或者如果你包括黑名单那么-75 ...