# Not able to compare two loops in a chain query

**URL:** https://discuss.elastic.co/t/not-able-to-compare-two-loops-in-a-chain-query/135488
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [June 12, 2018, 8:57am UTC](https://discuss.elastic.co/t/not-able-to-compare-two-loops-in-a-chain-query/135488 "2018-06-12T08:57:33Z")
**Posts on this page:** 1
**Showing post:** 10

<div class="post-metadata">

### Author: ![richcollier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richcollier/32/115035_2.png) [@richcollier](https://discuss.elastic.co/u/richcollier)
#### Post date: [June 13, 2018, 3:09pm UTC](https://discuss.elastic.co/t/not-able-to-compare-two-loops-in-a-chain-query/135488/10 "2018-06-13T15:09:08Z")

</div>

I've already recommended in [a different thread](https://discuss.elastic.co/t/how-to-compare-two-different-fields-value-of-two-different-index/132533/) that you should look at this post for ideas:

> [@Comparing values from 2 ML Jobs in watcher](https://discuss.elastic.co/t/comparing-values-from-2-ml-jobs-in-watcher/118882/4):
>
> Ok - after a little research, this could be done in probably two ways Method 1 - a script on the condition to see if there's an intersection of results from both queries "condition": { "script": "def second\_results = ctx.payload.second.hits.hits.stream().map(hit-\>hit.\_source.partition\_field\_value).collect(Collectors.toList()); return ctx.payload.first.hits.hits.stream().map(hit -\> hit.\_source.partition\_field\_value).filter(p-\>second\_results.contains(p)).collect(Collectors.toList()).si…

Why do you keep on asking? I'm confused...

---

_[View the full topic](https://discuss.elastic.co/t/not-able-to-compare-two-loops-in-a-chain-query/135488)._
