Matching users with similar interest tags using Firebase, Elasticsearch and Flashlight

Viewed 269

What is the best way to match documents by tags using elasticsearch using the following setup (or modifying the setup)?

I've got my users in a firebase database, they have associated tags that define their interests:

"users" : {
"bruce" : {
  "martial art" : "Jeet Kune Do",
  "name" : "Bruce Lee",
  "nick" : "Little Phoenix",
  "tags" : {
    "android" : true,
    "ios" : true
  }
},
"chan" : {
  "account_type" : "contractor",
  "martial art" : "Kung Fu",
  "name" : "Jackie Chan",
  "nick" : "Cannonball",
  "tags" : {
    "ios" : true
  }
},
"chuck" : {
  "martial art" : "Chun Kuk Do",
  "name" : "Carlos Ray Norris",
  "nick" : "Chuck"
}}

Using Flashlight + the Firebase admin SDK I'm keeping an index up to date on Bonsai/heroku, that supposedly will help me to match users with similar interests or related products.

"firebase": {
"aliases": {},
"mappings": {
  "user": {
    "properties": {
      "name": {
        "type": "string"
      },
      "tags": {
        "properties": {
          "android": {
            "type": "boolean"
          },
          "ios": {
            "type": "boolean"
          }
        }
      }
    }
  }
}...

For now I can query users with certain combination of tags:

{
"query": {
"bool": {
  "must" : {

    "type" : {
        "value" : "user"
    }
  },
  "should": [
             {
                "term": {
                  "tags.ios": true
                }
              },

               {
                "term": {
                  "tags.android": true
                }
              }


   ],
    "minimum_should_match" : 1
}}}

This is great but what I'm looking for is a way to:

  1. Given a user id find other users with similar tags ordered by _score.
  2. There will be other _type's apart from "user" using also tags, for example products so it would also be great to match products to users when they share some tags.

I get the feeling that because I'm absolutely new on elastic search I'm targeting this in the wrong way. Maybe the way the data is modeled?

Problem is that firebase kind of restricts this a lot, for instance I cannot have arrays, so that makes the tag modeling a bit weird ending in even more weird indexed data...maybe an approach could be to manipulate the data before inserting it to the index?

0 Answers
Related