不支持Elasticsearch排序选项

时间:2016-06-18 03:49:27

标签: ruby-on-rails elasticsearch

我在Rails中使用弹性搜索。我正在尝试按照他们花在降额上的总美元来对客户列表进行排序。这是我的红宝石代码:

=arrayformula(IF(len(B2:B)>0, IF(LEN(D2:D)>0,"Airtime","Accessory"),))

这将返回错误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) 我已尝试使用其他字段,以确保它不会对total_spent字段出错。感谢。

2 个答案:

答案 0 :(得分:1)

我不太确定,但我认为这可能与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)

答案 1 :(得分:0)

我们可以对该字段进行特定排序,请参阅https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html

所以我们可以使用like,

query = { 
    bool: {
      filter: { 
        term: { store_id: store.id } # Limits customers by current store
      }   
    },
    sort: { total_spent: { order: :desc }}   
  }   

response = Contact.search(query)