弹性搜索排序字符串不返回预期结果 [英] Elasticsearch sorting on string not returning expected results

查看:129
本文介绍了弹性搜索排序字符串不返回预期结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用多个单词对字符串字段进行排序时,Elasticsearch将分割字符串值并使用min或max作为排序值。 IE:当以值老虎眼的字段进行排序时,排序值为:眼睛,当按降序排序时,值为:Tiger。


让我说我有老虎之眼和死亡之轮作为我的索引中的条目,当我在这个领域上升排序时,我期望老虎之眼首先,因为E来到W之前,而是在这个领域进行排序时看到的死亡之轮首先出现,因为D是该术语的最小值,而E是老虎之眼的最小值。



有人知道如何关闭此行为,只允许在此字符串字段上进行常规排序?

解决方案

如果要在未分析的文档字段中排序,请提供mconlin,您需要指定index:not_analyzed按照您排序描述。但是,如果您希望能够将此字段标记为搜索,这篇文章由sloan显示了一个很好的例子。使用多字段保持两个不同的映射在一个字段是非常常见的弹性搜索。



希望这有帮助,让我知道如果我能提供更多的解释。


When sorting on a string field with multiple words, Elasticsearch is splitting the string value and using the min or max as the sort value. I.E.: when sorting on a field with the value "Eye of the Tiger" in ascending order, the sort value is: "Eye" and when sorting in descending order the value is: "Tiger".

Lets say I have "Eye of the Tiger" and "Wheel of Death" as entries in my index, when I do an ascending sort on this field, I would expect, "Eye of the Tiger" to be first, since "E" comes before "W", but what I'm seeing when sorting on this field, "Wheel of Death" is coming up first, since "D" is the min value of that term and "E" is the min value of "Eye of the Tiger".

Does anyone know how to turn off this behavior and just allow a regular sort on this string field?

解决方案

As mconlin mentioned if you want to sort on the unanalyzed doc field you need to specify "index": "not_analyzed" to sort as you described. But if you're looking to be able to keep this field tokenized to search on, this post by sloan shows a great example. Using multi-field to keep two different mappings for a field is very common in Elasticsearch.

Hope this helps, let me know if I can offer more explanation.

这篇关于弹性搜索排序字符串不返回预期结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆