我们有一个用例来根据Elasticsearch的自定义排序获取结果。
我们正在使用
Elasticsearch v 5.1.2
EX: 唯一编号和相应的文档在elasticsearch
中编制索引arr = [[1,"a b c"],[2, "x y z"], [3, "a x"], ......] # more than 1million
#client_obj is a elasticsearch object
for(i=0; i < arr.length; i++)
client_obj.index :index=> "test", :type=> 'texts' , :body=>{ :number=> arr[0],:text=>arr[1]}
arr = [1,3,200,100,2,10 ...]#1百万条款
从数组(arr),我期待结果作为Elasticsearch数组中排序的数字。我使用下面的API来获得结果。它适用于一小组数字,但如果数组大小超过500k,那么API中的功能块将会增加,而我的ES服务器将会崩溃。
#from and size value will very based on page number and size
GET /test/_search
{
"query": {
"function_score": {
"boost_mode": "replace",
"query": {
"constant_score": {
"query": {
"bool": {
"must": [ { "terms": { "number" : [1,3,200,100,2] }} ]
}
}
}
},
"functions": [
{ "filter": { "term": { "number": 1 } }, "weight" : 4 },
{ "filter": { "term": { "number": 3 } }, "weight" : 3 },
{ "filter": { "term": { "number": 200 } }, "weight" : 2 },
{ "filter": { "term": { "number": 100 } }, "weight" : 1 },
{ "filter": { "term": { "number": 2 } }, "weight" : 0 }
]
}
},
"_source": ["number"],
"size": 3,
"from": 0
}
我有以下查询
请帮我解决这个问题
提前致谢。