3

I have a User model, and user can have multiple interests with a numeric degree of how interested this person is in the subject matter. A sample user.to_indexed_json is:

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

And the mapping is:

  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

Given an array [{category_id, degree}, {category_id, degree} ] of multiple incoming interests (basically another user's interests), match all users that has these similar interests, and sorted (boosted) by the the degree. I tried with a lot of different query but unable to get results.

Do you have any idea how I can write the tire query? Is dis_max or nested query what I should be looking into more?

I wasn't able to write in Tire the query, so I wrote the raw JSON search query. I can get some results back, but it doesn't do any boosting

{
  "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}}
              ]
            }
          }
        }
      }
    }
  }
}

I'm new to ES so any help is really appreciated.

Alex Le
  • 499
  • 2
  • 14

0 Answers0