I know that the preference custome string is a function that allows you to search with the same shard, but every time you search, a different shard is searched, so the search results of search after are strange.
What should I do?
The preference option does have a _shards option as per the documentation. It doesn't look like the example usage _shards:2,3 matches the string in your example. Have you also made sure that the shards option is listed first?
Can I confirm that you're using Elasticsearch v6.x? That version is past EOL so we would strongly recommend upgrading if you can.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.