我使用以下脚本创建服务器端检索文档的随机顺序:
curl -POST 'http://localhost:9200/my_index/my_type/_search' -d '
{
"sort": {
"_script": {
"params": {},
"type": "number",
"order": "desc",
"script": "Math.random()"
}
},
"query": {
"match_all": {}
},
"fields": [
"field1",
"field2"
]
}'
该脚本使用常规搜索可以正常工作。
但是如果我尝试滚动浏览这个,search_type=scan
由于某种原因,使用分数似乎总是 0.0,我得到了原始的插入顺序。
我遵循的顺序是根据文档。首先,我打电话:
curl -POST 'http://localhost:9200/my_index/my_type/_search?pretty=true&search_type=scan&scroll=10m&size=4' -d '
{
"sort": {
"_script": {
"params": {},
"type": "number",
"order": "desc",
"script": "Math.random()"
}
},
"query": {
"match_all": {}
},
"fields": [
"field1",
"field2"
]
}'
接着:
curl -XGET 'http://localhost:9200/_search/scroll?pretty=true&scroll=10m&scroll_id=<the-previously-returned-id-here>
我究竟做错了什么?