# Count the number of document which contains either or both terms, and the term's values must be within a range

**URL:** <https://discuss.elastic.co/t/count-the-number-of-document-which-contains-either-or-both-terms-and-the-terms-values-must-be-within-a-range/177699>\
**Category:** Elasticsearch\
**Created:** [April 20, 2019, 9:14am UTC](https://discuss.elastic.co/t/count-the-number-of-document-which-contains-either-or-both-terms-and-the-terms-values-must-be-within-a-range/177699 "2019-04-20T09:14:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![twfx](https://avatars.discourse-cdn.com/v4/letter/t/5fc32e/32.png) [@twfx](https://discuss.elastic.co/u/twfx)\
**Post date:** [April 20, 2019, 9:14am UTC](https://discuss.elastic.co/t/count-the-number-of-document-which-contains-either-or-both-terms-and-the-terms-values-must-be-within-a-range/177699/1 "2019-04-20T09:14:12Z")

</div>

I want to count the number of document that

1. has either or both term A and term B
2. if term A or/and term B exist, the value is between a range.

I manage to write count for single term count as below and it returns correct count. However, how should I change it to include term "B" with an "OR" logic?

```
GET /propertyindex/_count
{
  "query": {
      "range": { 
        "A": {
          "gt": 1550160000, 
          "lte":1551369600}
      }
  }
}
```

---

<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 20, 2019, 9:28am UTC](https://discuss.elastic.co/t/count-the-number-of-document-which-contains-either-or-both-terms-and-the-terms-values-must-be-within-a-range/177699/2 "2019-04-20T09:28:25Z")

</div>

A bool query with a should clause with 2 inner queries?

---

<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 18, 2019, 9:28am UTC](https://discuss.elastic.co/t/count-the-number-of-document-which-contains-either-or-both-terms-and-the-terms-values-must-be-within-a-range/177699/3 "2019-05-18T09:28:30Z")

</div>

Closed on May 18, 2019, 9:28am UTC

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