Assign weightage for every document on the basis of sum of all document

HI all,

Please help me out below mentioned problem.

I want to give weightage for every document on the basis of sum of point value in a elasticsearch query.

Suppose i have 3 document and then i want to get sum of all document like sum = 1 + 4 + 2 = 7.
and then i want to give weightage for document 1 is (1/7 * 100) and document 2 is (4/7 * 100) and document 3 is (2/7 * 100).

PUT indexname/_doc/1
{
"doc":"a",
"point":1	
}

PUT indexname/_doc/2
{
"doc":"b",
"point":4	
}

PUT indexname/_doc/3
{
"doc":"c",
"point":2	
}
1 Like

I think you need to do that by running 2 queries.

The first to compute the sum.
The second with a function score script most likely.

Thanks for reply. But i want to calculate it with a single query to avoid 2 hits on my server. Is this possible with just one query?

No. I don't think so.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.