# Query to return only when one of the values greater than x but not when another value is also greater than x

**URL:** <https://discuss.elastic.co/t/query-to-return-only-when-one-of-the-values-greater-than-x-but-not-when-another-value-is-also-greater-than-x/357470>\
**Category:** Elasticsearch\
**Created:** [April 16, 2024, 2:38am UTC](https://discuss.elastic.co/t/query-to-return-only-when-one-of-the-values-greater-than-x-but-not-when-another-value-is-also-greater-than-x/357470 "2024-04-16T02:38:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![axiom](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@axiom](https://discuss.elastic.co/u/axiom)\
**Post date:** [April 16, 2024, 2:38am UTC](https://discuss.elastic.co/t/query-to-return-only-when-one-of-the-values-greater-than-x-but-not-when-another-value-is-also-greater-than-x/357470/1 "2024-04-16T02:38:02Z")

</div>

Hi, I'm new to Elastic Search and need some help if this query is possible to be done

Value in Table Format:

| value1 | value2 |
| --- | --- |
| 6000 | 2000 |
| 3000 | 3000 |
| 5000 | 8000 |
| 3002 | 3001 |
| 80 | 3500 |

only one of the values can be greater than 3000.  
get the query result if only one of value1 or value2 is greater than 3000, but not if both values exceeded 3000

Expected result is something like this:

| value1 | value2 |
| --- | --- |
| 6000 | 2000 |
| 3000 | 3000 |
| 80 | 3500 |

how do i modify this query to get this result?

> ```
> "query": {
> "bool": {
> "must":[
> {"range": {"value1": {"from": 0, "to": 3000}}},
> {"range": {"value2": {"from": 0, "to": 3000}}},   
> ]
> }
> },
> 
> ```

---

<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:** [April 16, 2024, 7:23am UTC](https://discuss.elastic.co/t/query-to-return-only-when-one-of-the-values-greater-than-x-but-not-when-another-value-is-also-greater-than-x/357470/2 "2024-04-16T07:23:46Z")

</div>

Welcome!

Try

```
   "query": {
       "bool": {
          "should":[
               {"range": {"value1": {"from": 0, "to": 3000}}},
               {"range": {"value2": {"from": 0, "to": 3000}}},   
           ]
       }
     },

```

---

<div class="post-metadata">

**Author:** ![axiom](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@axiom](https://discuss.elastic.co/u/axiom)\
**Post date:** [April 17, 2024, 2:29am UTC](https://discuss.elastic.co/t/query-to-return-only-when-one-of-the-values-greater-than-x-but-not-when-another-value-is-also-greater-than-x/357470/3 "2024-04-17T02:29:37Z")

</div>

Thank you for the quick reply. this works perfectly  
Turned out it's a fairly simple solution.. I need to do more reading with the documentations 😆

---

<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:** [May 15, 2024, 2:30am UTC](https://discuss.elastic.co/t/query-to-return-only-when-one-of-the-values-greater-than-x-but-not-when-another-value-is-also-greater-than-x/357470/4 "2024-05-15T02:30:29Z")

</div>

Closed on May 15, 2024, 2:30am UTC

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