Sorting by value in multivalued field in elasticsearch

本秂侑毒 提交于 2019-12-12 16:21:41

问题


I have a multivalue field with integers in the document, for example

{
   values: [1,2,3,4,5]
}

I apply range filter, for example from 2 to 4 and get list of document with values, contains 2,3,4. Now I'd like to sort results, and first return documents, which contains 3.

I could do it using script sorting:

{
  sort:{
    _script: {
      script: "doc['values'].getValues().contains(3) ? 0 : 1",
      type: "number"
    }
  }
}

But I don't like it's performance, because getValues() returns a List actually, and contains methods is O(n).

Are any better ways?

来源:https://stackoverflow.com/questions/24652769/sorting-by-value-in-multivalued-field-in-elasticsearch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!