# DSL - How to calculate a percentage value?

**URL:** <https://discuss.elastic.co/t/dsl-how-to-calculate-a-percentage-value/307584>\
**Category:** Elasticsearch\
**Created:** [June 19, 2022, 10:59am UTC](https://discuss.elastic.co/t/dsl-how-to-calculate-a-percentage-value/307584 "2022-06-19T10:59:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ely\_96](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ely_96/32/103816_2.png) [@Ely\_96](https://discuss.elastic.co/u/Ely_96)\
**Post date:** [June 19, 2022, 10:59am UTC](https://discuss.elastic.co/t/dsl-how-to-calculate-a-percentage-value/307584/1 "2022-06-19T10:59:54Z")

</div>

Hi guys,

i'm trying to caclulate the relationship between two values, but i can't get the desired value.  
This is my (DSL) \_search:

```auto
{
"size": 0,
	"query": {
		"bool": {
   			"filter": [
       			{"term": {"h.cat": "order"}}
       		]
   		}
	},
	"aggs": {
    	"rejects": {
        	"filter": {
            	"term": {
                	"c.order.status": "RJ"
                }
            }
        }
    }
}

```

I would like to show a KPI as:  
`count(rejects) / count(order) * 100`

- so the incidence of rejects on all orders.

I try also with "Bucket Script Aggregation", but I was not able to achieve my goal.

Could you please help me?

Thanks in advance!  
Ely

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [June 19, 2022, 3:53pm UTC](https://discuss.elastic.co/t/dsl-how-to-calculate-a-percentage-value/307584/2 "2022-06-19T15:53:42Z")

</div>

Hi @Ely_96 .

Could you provide more document information, are h.cat and c.order nested fields?

---

<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:** [July 17, 2022, 3:54pm UTC](https://discuss.elastic.co/t/dsl-how-to-calculate-a-percentage-value/307584/3 "2022-07-17T15:54:13Z")

</div>

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