In Elasticsearch I have two indexes, places
and users
. This is the mapping for places:
mappings: {
location: {
type: "geo_point"
}
}
And this is the mapping for users:
mappings: {
likes: {
type: "keyword"
},
seen: {
type: "keyword"
}
}
As you can see a user can like and see different places. Now I want to query places which a user has not seen or liked yet and want to show places which are liked by users who like similar places as the querying user first. This is the query I was able to come up with:
POST /places/_search
{
"_source": [
"id"
],
"size": 1,
"query": {
"function_score": {
"query": {
"bool": {
"must_not": [
{
"terms": {
"_id": {
"index": "users",
"id": "vu0E1rjJEqcgyfj29fwZ",
"path": "seen"
}
}
},
{
"terms": {
"_id": {
"index": "users",
"id": "vu0E1rjJEqcgyfj29fwZ",
"path": "likes"
}
}
}
],
"filter": {
"geo_distance": {
"distance": "200km",
"location": {
"lat": 52,
"lon": 13
}
}
}
}
},
"random_score": {},
"boost_mode": "replace"
}
}
}
However, at this moment this query just assigns a random score to all results. As I'm new to Elasticsearch I'm struggling to come up with a scoring function to achieve scoring places, that similar users have liked, higher, especially because the data about user likes is stored in a different index than the one I'm actually querying. What would be the best approach this problem? Is something like this even possible with my current data model?