# How to perform with condition divide math operation in elasticsearch

**URL:** https://discuss.elastic.co/t/how-to-perform-with-condition-divide-math-operation-in-elasticsearch/341329
**Category:** Elasticsearch
**Created:** [August 22, 2023, 6:54am UTC](https://discuss.elastic.co/t/how-to-perform-with-condition-divide-math-operation-in-elasticsearch/341329 "2023-08-22T06:54:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Huy\_Vu\_Quang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/huy_vu_quang/32/124818_2.png) [@Huy\_Vu\_Quang](https://discuss.elastic.co/u/Huy_Vu_Quang)
#### Post date: [August 22, 2023, 6:54am UTC](https://discuss.elastic.co/t/how-to-perform-with-condition-divide-math-operation-in-elasticsearch/341329/1 "2023-08-22T06:54:06Z")

</div>

I have a query like this  
how I perform a query in Elasticsearch with this condition  
if wager == 0 : payout/1 \>= multiplier  
else: payout/wager \>= multiplier  
filter multiplier according to this condition  
I wrote this query but it's not working

```auto
"query": {
            "bool": {
                "filter": [
                    {
                        "script": {
                            "script": {
                                "params": {
                                    "multiplier": "1"
                                },
                                "source": "if (doc['wager_usd'].value == 0) {return doc['payout_usd'].value / 1 >= params.multiplier;}return doc['payout_usd'].value / doc['wager_usd'].value >= params.multiplier;"
                            }
                        }
                    }
                ]
            }
        }

```

what I have wrong with this query, please help me!  
Thanks!

---

<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: [September 19, 2023, 6:55am UTC](https://discuss.elastic.co/t/how-to-perform-with-condition-divide-math-operation-in-elasticsearch/341329/2 "2023-09-19T06:55:02Z")

</div>

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