Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sorting by multi-valued fields #2634

Closed
martijnvg opened this issue Feb 8, 2013 · 1 comment
Closed

Allow sorting by multi-valued fields #2634

martijnvg opened this issue Feb 8, 2013 · 1 comment

Comments

@martijnvg
Copy link
Member

Add sorting support for fields that have multiple values per document (For example: string array or double array).
By default when sorting on a multi-valued field the lowest or highest value will be picked from the field values depending on the sort order.

It is possible to define what value should be picked when a document has multiple values in a field via the sort_mode option. The following options can be specified:

  • min - Pick the lowest value.
  • max - Pick the highest value.
  • sum - Use the sum of all values as sort value.
  • avg - Use the average of all values as sort value.

Example usage

curl -XPOST 'localhost:9200/_search' -d '{
   "query" : {
    ...
   },
   "sort" : [
      {"price" : {"order" : "asc", "sort_mode" : "avg"}}
   ]
}'

In the above example the field price has multiple prices per document. In this case the result hits will be sort by price ascending based on the average price per document.

@clintongormley
Copy link

Any chance of making the min or max value configurable? eg:

sort: [ { foo: { order: "asc", value: "max"} ]

martijnvg added a commit to martijnvg/elasticsearch that referenced this issue Feb 12, 2013
…the sort field is multi-valued.

The `min` and `max` sort modes are supported for all field types. Either the lowest value or the highest value is picked. In addition to that number based fields also support `sum` and `avg` as sort mode. If `sum` sort mode is used then all the values for a field and belonging to a document are added together and the result of that is used as sort value. If the `avg` sort mode is used then the average of all values for the sort field belonging to that document is used as sort value.

Relates to elastic#2634
martijnvg added a commit that referenced this issue Feb 12, 2013
…the sort field is multi-valued.

The `min` and `max` sort modes are supported for all field types. Either the lowest value or the highest value is picked. In addition to that number based fields also support `sum` and `avg` as sort mode. If `sum` sort mode is used then all the values for a field and belonging to a document are added together and the result of that is used as sort value. If the `avg` sort mode is used then the average of all values for the sort field belonging to that document is used as sort value.

Relates to #2634
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants