I have Elasticsearch documents for products with tags. Following is the structure of the documents:
{
"id": 'id-1',
"name: "prod-1",
"tags": [
{
"id": 'tag-id-1',
"name": 'tag-name-1'
},
{
"id": 'tag-id-2',
"name": 'tag-name-2'
}
]
}
What I want to do is:
Get all products with maximum overlapping tags (something like related questions in stackoverflow, assuming they have stored questions in Elasticsearch with tags). Output something like this:
{ "aggregations": { "products": [ { "key": "product-name-1", "tags": [ { "key": "tag-name-1", } { "key": "tag-name-2" } ] }, { "key": "product-name-2", "tags": [ { "key": "tag-name-2", } { "key": "tag-name-3" } ] }, ] } }
Get all tags grouped together with a tag maximum number of times.
{ "aggregations": { "tags": [ { "key": "tag-name-1", "tags": [ { "key": "tag-name-2", } { "key": "tag-name-3" } ] }, { "key": "product-name-2", "tags": [ { "key": "tag-name-1", } { "key": "tag-name-5" } ] }, ] } }
I am not very sure which type of aggregation methods to use. Any help will be useful.
Thanks.