# How to Compare two different fields value of two different index?

**URL:** https://discuss.elastic.co/t/how-to-compare-two-different-fields-value-of-two-different-index/132533
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [May 18, 2018, 7:28pm UTC](https://discuss.elastic.co/t/how-to-compare-two-different-fields-value-of-two-different-index/132533 "2018-05-18T19:28:42Z")
**Posts on this page:** 1
**Showing post:** 18

<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: [May 24, 2018, 9:44pm UTC](https://discuss.elastic.co/t/how-to-compare-two-different-fields-value-of-two-different-index/132533/18 "2018-05-24T21:44:18Z")

</div>

This is probably helpful:

> [@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…

---

_[View the full topic](https://discuss.elastic.co/t/how-to-compare-two-different-fields-value-of-two-different-index/132533)._
