简体   繁体   English

带有Order.ignoreCase()的Spring Elastic Search不区分大小写排序

[英]Spring Elastic Search case insensitive sorting with Order.ignoreCase() not working

I am trying to sort list of Person by their first name. 我正在尝试按人员的名字对人员列表进行排序。 using Open Declaration org.springframework.data.domain.Sort.Order.Order.ignoreCase() as shown below. 使用开放声明org.springframework.data.domain.Sort.Order.Order.ignoreCase() ,如下所示。

    import org.springframework.data.domain.Sort;
    import org.springframework.data.domain.Sort.Direction;
    import org.springframework.data.domain.Sort.Order;

    Order sortOrfer = new Order(Sort.Direction.ASC, "firstName").ignoreCase();

In ES repository, I have person name with different cases. 在ES信息库中,我有不同情况的人名。 for example. 例如。

  • Sachin 萨钦
  • ajai 阿杰
  • Dhoni 多尼

I am expecting the sorted data as shown below. 我期望如下所示的排序数据。

  • ajai 阿杰
  • Dhoni 多尼
  • Sachin 萨钦

But the data is sorted as below, which is not correct(not expected), 但是数据排序如下,这是不正确的(不期望),

  • Dhoni 多尼
  • Sachin 萨钦
  • ajai 阿杰

the root cause of this behavior is that for ajai first letter is in small case. 此行为的根本原因是,对于ajai首字母小写。 According to ES cases insensitive sorting is supported, Can any one tell me how can I fix this? 根据ES的情况,支持不敏感排序,有人可以告诉我如何解决此问题吗?

The package you are calling is part of core spring data, not ES specific. 您正在调用的包是核心spring数据的一部分,而不是ES特定的。 Elasticsearch must be setup with the proper mapping, and indexed with those settings. Elasticsearch必须使用正确的映射进行设置,并使用这些设置编制索引。 As far as I know, Elasticsearch has no such ability in Query DSL to sort the way you're asking (alphabetical vs lexicographical). 据我所知,Elasticsearch在查询DSL中没有这样的功能来对您的询问方式进行排序(字母顺序还是词典顺序)。 If you are trying to sort on the client-side, that would only sort the results returned for the first page, probably not what you are intending. 如果您尝试在客户端进行排序,那么只会对返回首页的结果进行排序,可能不是您想要的结果。

Also see this post which worked for us. 另请参阅这篇对我们有用的帖子

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

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