ExAliyunOts.Search.group_by_range

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

group_by_range(group_name, field_name, ranges, options \\ [])

View Source

Specs

group_by_range(group_name(), field_name(), ranges :: list(), options()) :: map()

The :group_bys results are grouped according to the range of a field, if the field value is within a range, it will be put into a group, finally, 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

Example

import MyApp.TableStore

search "table", "index_name",
  search_query: [
    query: ...,
    group_bys: [
      group_by_range("group_name", "price",
        [
          {0, 18},
          {18, 50}
        ],
        sub_group_bys: [
          group_by_field("sorted_by_type", "type",
            sort: [
              group_key_sort(:asc)
            ]
          )
        ],
        sub_aggs: [
          agg_distinct_count("distinct_price", "price")
        ]
      )
    ]
  ]

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

Please notice that each range item(as a tuple, according to {from, to}) of ranges, its start is greater than or equal to from, and its ending is less than to, the range interval value can be integer or float.

Options

  • :sub_group_bys, optional, add sub GroupBy type aggregations.
  • :sub_aggs, optional, add sub statistics.