Elasticsearch custom function

(Fahad Hasan Ratul) #1

Lets say I have a the following tables:

products: id, name, latitude and longitude
users: id, name, latitude, longitude
interests: id, name
user_interests: user_id, interest_id

These gets inserted/updated into elasticsearch whenever they are created/edited using model observers.

Now I want to make a custom script/scoring function in elastic search which will return me a matching score when a user is searching for a product. The scoring will be based on distance between users location and product, user interests and product name match etc etc.

Being new to elastic search, whats the right approach of implementing this? Any tutorial, online resources or examples are highly appreciated.

PS: I am using PostgreSQL as a database. I can create a function there called get_match(product_id, user_id) which returns a number (0-100) based on matching criteria and do something like:

//psuedo sql 
select p.name, get_match(p.id, u.id) as match
from products p, users u
order by match desc

I want to achieve a similar functionality in elasticsearch if possible.

(Mark Walkom) #2

You cannot do joins like that in ES, you have to structure your data to take the relations into account or grab the data from each index and then mash them up externally.

(system) #3