[英]Elasticsearch sort option not supported
我在Rails中使用彈性搜索。 我正在嘗試按花費的總金額遞減的方式對客戶列表進行排序。 這是我的紅寶石代碼:
query = {
bool: {
filter: {
term: { store_id: store.id } # Limits customers by current store
}
}
}
sort = {
sort: { "total_spent": { order: "desc" }}
}
response = Contact.search(query: query, sort: sort)
返回此錯誤, sort option [total_spent] not supported
的錯誤我嘗試了其他字段,以確保total_spent字段不僅有問題。 謝謝。
我不太確定,但是我認為這可能與ES :: DSL的錯誤使用有關。
嘗試此操作會發生什么:
query = {
bool: {
filter: {
term: { store_id: store.id } # Limits customers by current store
}
}
}
sort = {
sort: [{ "total_spent": { order: "desc" }}] #https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html
}
response = Contact.search(query, sort)
我們可以針對特定領域進行排序,請參閱https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html 。
這樣我們就可以使用
query = {
bool: {
filter: {
term: { store_id: store.id } # Limits customers by current store
}
},
sort: { total_spent: { order: :desc }}
}
response = Contact.search(query)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.