How to use the searchkit.CardinalityMetric 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
buildSharedQuery(query: Object) {
      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(
github PAK90 / mtg-hunter / src / FacetAccessor.js View on Github external
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 mitodl / micromasters / static / js / components / search / NestedAggregatingMenuFilter.js View on Github external
buildOwnQuery(query) {
    if (!this.loadAggregations) {
      return query
    } else {
      return query.setAggs(
        FilterBucket(
          this.uuid,
          this.createAggFilter(query),
          ...this.fieldContext.wrapAggregations(
            this.getTermsBucket(query),
            CardinalityMetric(`${this.key}_count`, this.key)
          )
        )
      )
    }
  }
github CRUKorg / cruk-searchkit / src / components / search / date / CRUKSearchkitDateRangeAccessor.jsx View on Github external
buildOwnQuery(query) {
    const val = this.state.getValue();
    const min = val.min;
    const max = val.max;

    let otherFilters = query.getFiltersWithoutKeys(this.key);
    let filters = BoolMust([
      otherFilters,
      RangeQuery(this.options.field,{
        gte:min,
        lt: this.addOneDay(val.max),
        format: 'yyyy-MM-dd'
      })
    ]);

    const metric = CardinalityMetric(this.key, this.options.field);

    return query.setAggs(FilterBucket(
      this.key,
      filters,
      metric
    ));
  }
}
github mitodl / micromasters / static / js / components / search / FinalGradeRangeFilter.js View on Github external
createInnerRangeBucket() {
    let metric
    if (this.options.loadHistogram) {
      metric = HistogramBucket(this.key, this.options.field, {
        interval:        this.getInterval(),
        min_doc_count:   0,
        extended_bounds: {
          min: this.options.min,
          max: this.options.max
        }
      })
    } else {
      metric = CardinalityMetric(this.key, this.options.field)
    }
    return metric
  }
}