# Elastic search query group only data where none of the fields contain x

**URL:** <https://discuss.elastic.co/t/elastic-search-query-group-only-data-where-none-of-the-fields-contain-x/155703>\
**Category:** Elasticsearch\
**Created:** [November 7, 2018, 11:23am UTC](https://discuss.elastic.co/t/elastic-search-query-group-only-data-where-none-of-the-fields-contain-x/155703 "2018-11-07T11:23:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomaz\_Bratanic1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomaz_bratanic1/32/45111_2.png) [@Tomaz\_Bratanic1](https://discuss.elastic.co/u/Tomaz_Bratanic1)\
**Post date:** [November 7, 2018, 11:23am UTC](https://discuss.elastic.co/t/elastic-search-query-group-only-data-where-none-of-the-fields-contain-x/155703/1 "2018-11-07T11:23:58Z")

</div>

The structure of my logs looks like this:

{deviceID:"xx", charger:"xy", date: "yy", battery: 5}

Is it possible to have a ES query that.

1. Takes last 24h
2. Excludes devices where any of the log in the last 24h had charger value = 2
3. Returns logs

I don't know how to do the second step where you exclude all the logs from a single device if any of the logs had a specific value.

Thanks

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [November 7, 2018, 4:20pm UTC](https://discuss.elastic.co/t/elastic-search-query-group-only-data-where-none-of-the-fields-contain-x/155703/2 "2018-11-07T16:20:32Z")

</div>

I would try ...

```auto
{
  "query": {
    "bool": {
      "filter": {
              "range": {
                "date": {
                  "gte": "now-1d",
                  "lte": "now"
                }
              }
      },
      "must_not": [
        {
          "match": {
            "charger": "2"
          }
        }
      ]
    }
  }
}

```

Alternatively, you can combine `filter` for `charge field` if it is non-analyzed and you dont want to score it, helps with caching too, along with `range` filter.

---

<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:** [December 5, 2018, 4:20pm UTC](https://discuss.elastic.co/t/elastic-search-query-group-only-data-where-none-of-the-fields-contain-x/155703/3 "2018-12-05T16:20:35Z")

</div>

Closed on December 5, 2018, 4:20pm UTC

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