ExAliyunOts.Search.field_sort
field_sort
, go back to ExAliyunOts.Search module for more information.
Specs
field_sort(field_name(), options()) :: map()
Sort by the value of a column, use it in the nested :sort
option of :search_query
option in ExAliyunOts.search/4
.
Example
import MyApp.TableStore
search "table", "index_name",
search_query: [
query: ...,
sort: [
field_sort("field_a", order: :desc)
]
]
If there's a nested type of search index, and they are a integer or float list, we can use :mode
to
sort according to the minimum/maximum/average value of the list, by default it's :nil
.
For example, there's a nested type as "values" field, the following query will find "values" field existed as matched rows, and sort by the minimum value of list items.
Example
import MyApp.TableStore
search "table", "index_name",
search_query: [
query: exists_query("values"),
sort: [
field_sort("values", mode: :min)
]
]
Still for nested type of search index, we can sort by the nested value via :nested_filter
option, for example,
sort by the value of "content.header" in :desc
order.
Example
import MyApp.TableStore
search "table", "index_name",
search_query: [
query: nested_query(
"content",
[
exists_query("content.header")
]
),
sort: [
field_sort("content.header",
order: :desc,
nested_filter: nested_filter(
"content",
prefix_query("content.header", "header")
)
)
]
]
Please ensure that the query criteria matched will participate in sorting, if there exists any not matched case will lead to uncertainty of sorting results.
Options
:mode
, optional, available options are:min
|:max
|:avg
, by default it's:nil
;:order
, optional, available options are:asc
|:desc
, by default it's:asc
;:nested_filter
, optional, seenested_filter/2
for details.