Search UI: Aggs in UI state and request?


  • @elastic/search-ui-elasticsearch-connector: “1.13.0”
  • @elastic/react-search-ui: “1.13.0”


  • ES

Hello, thank you for your work on all of these packages!

Wondering if there is more recommended way to work with Aggs than my current approach below. I’m using the example repo app-search-reference-ui to try out these packages.

Aggs in API Requests

I see that a top level aggs:{} prop is included in the request payload. But from looking at how the request is built in Request.ts, it seems aggs is not one of the props plucked from queryConfig or requestState.

Aggs in UI State

In the API docs I see there are functions exposed for updating filters, searchTerm, sort, etc but I’m not seeing any docs about maintaining and updating state for Aggs.

Current Workaround

I’m keeping the queryConfig in my app state. Using a postProcessFn (passed as 2nd arg to my ES connector instance), I read from that queryConfig and modify the request body to include aggs.

const customizeESRequestBody = (requestBody, requestState, queryConfig) => {
requestBody.aggs = {
return requestBody;

hey @esTest

Could you share what type of aggregations you are hoping to add into the requestBody / maintain and share a typical Elasticsearch request with the aggregations you want? Could you also share what use-case you're hoping to achieve with controlling aggregations?

Behind the scenes, the elasticsearch-connector will use the facet configuration to generate the aggregations needed to power those facets. See here for more information Configuration | Elastic Documentation


Thanks for explaining @joemcelroy, I didn't realize the connector would translate facets to aggs.

Here are some example aggs I wanted to apply to most result sets:

  • sum a field
  • avg a field

Is it possible to express those ^ using the facet API? From checking the code I see the 3 supported facet types are: value, range, location.

Thanks again, cheers!

hey @esTest, from what you said, my understanding is that you want to display a value which uses sums / avg field values in the result set? Its an interesting use-case but not something search-ui supports unfortunately.

The only thing I can suggest would be to query Elasticsearch separately for these field aggregation values and display them separately, leaving search-ui to handle the rest.

@joemcelroy Thanks again for the replies. I'm planning to use react-search-ui with a custom connector. Cheers!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.