Why does this ElasticSearch scan and scroll keep returning the same scroll id?

What you have above is correct.

The scroll_id may or may not be the same across subsequent scroll request. But the result set (hits) is definitively different in subsequent scroll calls .

The scroll_id may change over the course of multiple calls and so it is required to always pass the most recent scroll_id as the scroll_id for the subsequent request.


In most of the cases scroll_id will remain same and it may change sometime, have a look at the end of this page https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/search_operations.html in the comments of code sample it says:

// When done, get the new scroll_id

// You must always refresh your _scroll_id! It can change sometimes

It means getting same scroll id for subsequent requests is fine but not mandatory.