[英]Elasticsearch sort option not supported
I'm using elastic search in Rails. 我在Rails中使用弹性搜索。 I am trying to sort a list of customers by their total dollars spent descending.
我正在尝试按花费的总金额递减的方式对客户列表进行排序。 This is my ruby code:
这是我的红宝石代码:
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)
This returns with an error of sort option [total_spent] not supported
I've tried with other fields to make sure it wasn't just something wrong with the total_spent field. 返回此错误,
sort option [total_spent] not supported
的错误我尝试了其他字段,以确保total_spent字段不仅有问题。 Thanks. 谢谢。
I'm not really sure, but I think this may be related to incorrect usage of the ES::DSL. 我不太确定,但是我认为这可能与ES :: DSL的错误使用有关。
What happens when you try this: 尝试此操作会发生什么:
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)
We can sort specific to the field, refer https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html . 我们可以针对特定领域进行排序,请参阅https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html 。
so we can use like, 这样我们就可以使用
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.