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

**URL:** <https://discuss.elastic.co/t/assign-weightage-for-every-document-on-the-basis-of-sum-of-all-document/163723>\
**Category:** Elasticsearch\
**Created:** [January 10, 2019, 11:34am UTC](https://discuss.elastic.co/t/assign-weightage-for-every-document-on-the-basis-of-sum-of-all-document/163723 "2019-01-10T11:34:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bharatbhushan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bharatbhushan/32/10960_2.png) [@bharatbhushan](https://discuss.elastic.co/u/bharatbhushan)\
**Post date:** [January 10, 2019, 11:34am UTC](https://discuss.elastic.co/t/assign-weightage-for-every-document-on-the-basis-of-sum-of-all-document/163723/1 "2019-01-10T11:34:35Z")

</div>

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	
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2019, 1:20pm UTC](https://discuss.elastic.co/t/assign-weightage-for-every-document-on-the-basis-of-sum-of-all-document/163723/2 "2019-01-10T13:20:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bharatbhushan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bharatbhushan/32/10960_2.png) [@bharatbhushan](https://discuss.elastic.co/u/bharatbhushan)\
**Post date:** [January 10, 2019, 1:33pm UTC](https://discuss.elastic.co/t/assign-weightage-for-every-document-on-the-basis-of-sum-of-all-document/163723/3 "2019-01-10T13:33:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2019, 1:46pm UTC](https://discuss.elastic.co/t/assign-weightage-for-every-document-on-the-basis-of-sum-of-all-document/163723/4 "2019-01-10T13:46:35Z")

</div>

No. I don't think so.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 7, 2019, 1:46pm UTC](https://discuss.elastic.co/t/assign-weightage-for-every-document-on-the-basis-of-sum-of-all-document/163723/5 "2019-02-07T13:46:42Z")

</div>

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