How to use the searchkit.TermsBucket function in searchkit

To help you get started, we’ve selected a few searchkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mitodl / micromasters / static / js / components / search / WithReverseNestedAccessor.js View on Github external
const modifiedQuery = super.buildSharedQuery(query)
      /**
       *  Modify query to perform aggregation on unique users,
       *  to avoid duplicate counts of multiple work histories or education items
       *  for the same user
       **/
      const pieces = nestedField.split(".")
      if (pieces.length !== 3) {
        throw new Error(`Assumed three pieces but found ${pieces.length}`)
      }

      const cardinality = CardinalityMetric("count", "user_id")
      const aggsContainer = AggsContainer(countName, { reverse_nested: {} }, [
        cardinality
      ])
      const termsBucket = TermsBucket(
        nestedField,
        nestedField,
        {},
        aggsContainer
      )

      const nestedBucket = NestedBucket(
        "inner",
        `${pieces[0]}.${pieces[1]}`,
        termsBucket
      )
      return modifiedQuery.setAggs(
        AggsContainer(
          `${this.uuid}`,
          {
            filter: {}
github mitodl / micromasters / static / js / components / search / NestedAggregatingMenuFilter.js View on Github external
function ReverseNestedTermsBucket(key, field, options) {
  const reverseNestedAgg = AggsContainer(REVERSE_NESTED_AGG_KEY, {
    reverse_nested: {}
  })
  return TermsBucket(key, field, options, reverseNestedAgg)
}
github PAK90 / mtg-hunter / src / FacetAccessor.js View on Github external
buildOwnQuery(query){
    if (!this.loadAggregations){
      return query
    } else {
      var filters = this.state.getValue()
      let excludedKey = (this.isOrOperator()) ? this.uuid : undefined
      return query
        .setAggs(FilterBucket(
          this.uuid,
          query.getFiltersWithoutKeys(excludedKey),
          TermsBucket(this.key, this.key, omitBy({
            size:this.size,
            order:this.getOrder(),
            include: this.options.include,
            exclude: this.options.exclude,
            min_doc_count:this.options.min_doc_count
          }, isUndefined)),
          CardinalityMetric(this.key+"_count", this.key)
        ))
    }
  }
}
github searchkit / searchkit / packages / searchkit-autosuggest / src / datasources / HierarchicalRefinementDatasource.ts View on Github external
BoolMust([
                NestedQuery(field, regexpQuery)
            ]),
            NestedBucket("children", field,
                FilterBucket("filtered",
                    BoolMust([
                        regexpQuery,
                        {
                            "range": {
                                [field + ".level"]: {
                                    gte: startLevel
                                }
                            }
                        }
                    ]),
                    TermsBucket("terms", field + ".value", {
                        size: this.options.size
                    },
                        TopHitsMetric("hits", {
                            _source: [field + ".ancestors", "ancestors"],
                            size: 1
                        }))
                )
            )
        ))
    }