Compare fields of different documents in the same index

I don't really understand this use case, but because it needs to run in two passes you have limited options:

  1. The only client-side way to run two passes in Kibana is using Canvas. You can make a request, and then script something to make another request
  2. In a batch process, you can set a field like doc.hasMatching: true in documents and then use this in Kibana
  3. You might be able to do this using a Continuous Transform