Skip previous queries

I'm developing a PHP script that use Elasticsearch. The use of this script is comparing two "companies" to see if they share any connection. The user will input two companies and the script will query Elasticsearch and get all results associated with those. It will then take the results and start a new search using fields from those results. This will repeat until there are no more results and you have all the connections between the companies.

One problem with doing this is that those fields that are searched could contain the same values that have already been searched for. If we search for "company A" and get "company B" in the field, and then the script search cor "company B" and finds it connection with "company A", it'll search for "company A" again and begin an infinite(?) loop.

Is there a way to use Elasticsearch or PHP to skip queries that are the same as ones that have already been performed? Or are there any mechanics of Elasticsearch that helps with this problem?

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