[英]Elasticsearch query with sort by script [syntax]
我正在嘗試使用此處建議的隨機腳本對查詢進行排序
我很難驗證和運行查詢,因為它不斷向我返回錯誤。
我正在運行的查詢是:
{
"sort": {
"_script": {
"script": "(doc['_id'].value + salt).hashCode()",
"type": "string",
"params": {
"salt": "some_random_string"
},
"order": "asc"
}
},
"query": {
"filtered": {
"filter": {
"and": [
{
"exists": {
"field": "location"
}
},
{
"terms": {
"streamIds": [
796
]
}
}
]
}
}
}
}
沒有排序的查詢將工作並返回結果。
我究竟做錯了什么?
發現Elasticsearch從1.4.3開始禁用腳本,這就是為什么它不起作用的原因。
起作用的代碼:
{
"query": {
"function_score": {
"query": {
"filtered": {
"filter": {
"and": [
{
"exists": {
"field": "location"
}
},
{
"terms": {
"streamIds": [
796
]
}
}
]
}
}
},
"random_score": {}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.