简体   繁体   English

弹性搜索排序的正确方法是什么?

[英]What is the proper way to sort in elasticsearch?

I am using elasticsearch with a ruby application via Tire gem. 我正在通过Tire gem将Elasticsearch与红宝石应用程序一起使用。 Here is my index 这是我的索引

mapping do
  indexes :title
  indexes :views_count, type: 'integer'
  indexes :created_time, type: 'date'
end

And my query:- 而我的查询:

News.tire.search load: true do 
  query {all}
  sort { by :views_count, 'desc'}
end

This is pretty good and looks it will be works well. 这非常好,看起来会很好用。 However, There is unexpected result. 但是,出现意外结果。 It treats numbers as strings. 它将数字视为字符串。 That means it will consider '33' less than '4'. 这意味着它将认为“ 33”小于“ 4”。 I want to tell elasticsearch to treat them as integers not strings. 我想告诉elasticsearch将它们视为整数而不是字符串。

And the same thing is happening with created_time but I did not notice the pattern it sorts with. 而且created_time也发生了同样的事情,但是我没有注意到排序的模式。 I think I should pass type or something. 我想我应该通过类型或类似的东西。 So, any body can help me? 那么,有什么机构可以帮助我吗?

Thank you in advance. 先感谢您。

我的错误是我只更新索引,而不更新索引的映射,因为在创建映射之前发现类型参数之前,存在映射。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM