The basic idea is simple, we have some external kv pairs imply friend id and corresponding intimacy value that can pass to elasticsearch. We want to query first and get some match documents with corresponding text relevance score in descending order, then we select top-3 friend with highest intimacy from top-N match docuements by using external kv-pairs as recommendation items, sort top-3 recommendation items by previous text relevance score, and then sort other none-recommendation documents also by previous text relevance score and put these documents behind 3 recommendation items.
I think after sort the documents by text relevance, I can write a rescore script to lift the score of 3 documents that has the highest intimacy, suppose the origin text relevance score is xxx, within the rescore script with N window_size I can lift the _score to 1000xxx, and other non-recommend docs's score remain the same, so after rescore the docs with top-3 highest intimacy can be put on top-3 result with text relevance in descending order, and others also rank by text relevance in descending order. But things changed after with several shard and coordinate node, since each shard(suppose we have 4 shard) will lift 3 docs, on coordinate node's side 3x4-3 candidate recommend docs will lose after merge and need to downgrade their _score and resort. But rescore can't run on coordinate node. And I think sort script can both run on data node and coordinate node(though the ES manual doesn't say it clearly), but it seems window_size can't be applied to sort script to get top-N text relevance on data-node. So is there any way to achieve this logic?