# Query Predicated on Another

**URL:** <https://discuss.elastic.co/t/query-predicated-on-another/101205>\
**Category:** Elasticsearch\
**Created:** [September 20, 2017, 3:47pm UTC](https://discuss.elastic.co/t/query-predicated-on-another/101205 "2017-09-20T15:47:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![plemarquand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/plemarquand/32/17205_2.png) [@plemarquand](https://discuss.elastic.co/u/plemarquand)\
**Post date:** [September 20, 2017, 3:47pm UTC](https://discuss.elastic.co/t/query-predicated-on-another/101205/1 "2017-09-20T15:47:12Z")

</div>

Hi,

I have two indexes, one called `warnings` and another, `warning_settings`.

`warning_settings` consists of documents with that simply contain a warning `id` and `disabled: true/false`.

I'd like to query all the `warnings` that don't have a corresponding `warning_settings` document with `disabled: true`, and then do your usual aggregations over that data to generate some nice visualizations in Kibana.

Is this possible with ES? I've got it working as a two step process, but doing this from Kibana seems to require a single query.

Here are the two queries I'm making right now:

```auto
GET warning_settings/_search
query: {
    match: {
       disabled: true,
    },
}

```

```auto
GET warnings/_search
query: {
    ...
    must_not: {
      terms: {
        id: [... ids returned from first query],
      },
    },
  },
},

```

Any help is greatly appreciated!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 22, 2017, 6:53am UTC](https://discuss.elastic.co/t/query-predicated-on-another/101205/2 "2017-09-22T06:53:54Z")

</div>

That's not possible from Elasticsearch or Kibana.  
You could do it with a Watch (via Alerting), but otherwise you'd need to do it in an external client.

---

<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:** [October 20, 2017, 6:54am UTC](https://discuss.elastic.co/t/query-predicated-on-another/101205/3 "2017-10-20T06:54:06Z")

</div>

Closed on October 20, 2017, 6:54am UTC

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