We are working on a recommendation system which will return the recommendation with highest number of matched attribute based on the input persons attribute.
For Example:
Below are the recommendation documents created in elastic search:
Document:
/recommendation/1
{
"Age":"25",
"Country":"AA",
"Height":"170",
"RecommendationType":"A"
"isRecommendationActive": true
}
/recommendation/2
{
"Age":"25",
"Country":"AA",
"Height":"150",
"RecommendationType":"A"
"isRecommendationActive": true
}
/recommendation/3
{
"Age":"25",
"RecommendationType":"A",
"isRecommendationActive": true
}
/recommendation/4
{
"Age":"25",
"Weight":"170",
"Country":"AA",
"Height":"170",
"RecommendationType":"B",
"isRecommendationActive": true
}
/recommendation/5
{
"City":"PPP"
"RecommendationType":"C",
"isRecommendationActive": true
}
Below is the input object that will be used to query the elastic search:
Person:
Name: ABC,
Age: 25,
Height: 170,
Weight: 60,
Country: AA,
RecommendationType:B,
isRecommendationActive: true,
City: ZZZ
Expected result from ES should be (Sorted in terms of score):
/recommendation/1
{
"Age":"25",
"Country":"AA",
"Height":"170",
"RecommendationType":"A"
"isRecommendationActive": true
}
/recommendation/3
{
"Age":"25",
"RecommendationType":"A",
"isRecommendationActive": true
}
Reason for document 2, 4 and 5 should not be shown is:
Document 2: Even though it matches most of the attributes, it doesn't match "Height":"150" as the input persons height is 170
Document 4: Even though it matches most of the attributes, it doesn't have the "RecommendationType":"A"
Document 5: None of the attribute matches
So the bottom line is, the result should only include if all the attributes in the document matches the attributes in the input. And the result should be sorted based on the number of attributes present in each document.
Ex: Document 1 has more value as it has 5 attributes whereas Document 3 has only 3 attributes
I tried several kinds of nested query, scripts, etc, but none of them resulted in the result I desired. So can we solve this problem using elastic search?
I have seen this post: Subsets . But I was wondering if there is a way to solve without scripting as AWS ES doesn't support scripting.