[英]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.