3

我有一个用户模型,用户可以有多种兴趣,这个人对主题的兴趣程度有多大。一个样本user.to_indexed_json 是:

{
   // user attributes
  interests: [
    {category_id: 1, degree: 1}
    {category_id: 2, degree: 3}
    // more category stuff here
  }
}

映射是:

  tire do
    mapping do
      indexes :name,   type: 'string', analyzer: 'snowball'
      indexes :email,   type: 'string', analyzer: 'snowball'
      indexes :lat_lon, type: 'geo_point'
      indexes :interests, type: 'nested', :category_id => :number
    end
  end

给定一个包含多个传入兴趣(基本上是另一个用户的兴趣)的数组 [{category_id, degree}, {category_id, degree}],匹配所有具有这些相似兴趣的用户,并按度数排序(提升)。我尝试了很多不同的查询,但无法获得结果。

您知道如何编写轮胎查询吗?是dis_max嵌套查询还是我应该研究的更多内容?

我无法在 Tire 中编写查询,所以我编写了原始 JSON 搜索查询。我可以得到一些结果,但它没有任何提升

{
  "query": {
    "filtered": {
      "query": { "match_all": {} },
      "filter": {
        "nested": {
          "path": "interests",
          "query": {
            "bool": {
              "minimum_number_should_match": 1,
              "should": [
                {"match": { "interests.category_id": 7}
                ,{"match": {"interests.category_id": 1}}
                ,{"match": {"interests.category_id": 10}}
              ]
            }
          }
        }
      }
    }
  }
}

我是 ES 的新手,所以非常感谢任何帮助。

4

0 回答 0