How to query new documents only? Order by _uid?

Hi,

in order to do what you described you somehow have to create a field to establish this order in your application. The problem with the '_id' or '_uid' field is that they are not really usable in range queries which you probably what to have for the _id > $lastQueriedID part.

If you control the indexing of the documents you can introduce your own kind of "autoincrement" id and store this along with your document in its own numeric field. The you can use this to scope your query to only return the "new" ones like you already suggested (provided you have a way of storing your lastQueriedID on your applications side).

Other ways you could do this is e.g. add an aditional timestamp field in your document ingestion process (e.g. logstash or an ingest node) and use that as a value that monotonically increases so you can use it in the same way as an auto-increment id for ordering.

This all assumes that you have a single point (or process) where document enter your system, so you can maintain an increasing counter. This should still work if you are moving from one node to a cluster as long as you control this on your application side.