You're seeing just the function group_by_field, go back to ExAliyunOts.Search module for more information.
Link to this function

group_by_field(group_name, field_name, options \\ [])

View Source


group_by_field(group_name(), field_name(), options()) :: map()

The :group_bys results are grouped according to the value of a field, the same value will be put into a group, finally, the value of each group and the number corresponding to the value will be returned.

We can set it in the nested :group_bys option of :search_query option in ExAliyunOts.search/4.

Official document in Chinese | English


import MyApp.TableStore

search "table", "index_name",
  search_query: [
    query: ...,
    group_bys: [
      group_by_field("group_name", "type",
        size: 3,
        sub_group_bys: [
          group_by_field("sub_gn1", "is_actived")
        sort: [
      group_by_field("group_name2", "is_actived")

The group_name can be any business description string, when get the grouped results, we need to use it to fetch them.


  • :sort, optional, add sorting rules for items in a group, by default, sort in descending order according to the quantity of items in the group. Support group_key_sort/1 | row_count_sort/1 | sub_agg_sort/2 sort.
  • :size, optional, the number of returned groups.
  • :sub_group_bys, optional, add sub GroupBy type aggregations.
  • :sub_aggs, optional, add sub statistics.