If the query results on shards exceed the upper limit of records that can be returned (default value: 10000), you need to increase the limit by changing the value of search.max_buckets.
PUT _cluster/settings { "persistent": { "search.max_buckets": 20000 } }