Skip to content

Latest commit

 

History

History
715 lines (413 loc) · 31 KB

API.md

File metadata and controls

715 lines (413 loc) · 31 KB

Bodybuilder

The main builder class.

Examples

var body = new Bodybuilder()
  .query('match', 'text', 'this is a test')
  .build()

build

Constructs the elasticsearch query body in its current state.

Parameters

  • version String Version to generate.

Returns Object Query body.

sort

Set a sort direction on a given field.

Parameters

  • field String Field name.
  • direction [String] A valid direction: 'asc' or 'desc'. (optional, default 'asc')

Returns Bodybuilder Builder class.

from

Set a from offset value, for paginating a query.

Parameters

  • quantity Number The offset from the first result you want to fetch.

Returns Bodybuilder Builder class.

size

Set a size value for maximum results to return.

Parameters

  • quantity Number Maximum number of results to return.

Returns Bodybuilder Builder class.

rawOption

Set any key-value on the elasticsearch body.

Parameters

Returns Bodybuilder Builder class.

filter

Apply a filter of a given type providing all the necessary arguments, passing these arguments directly to the specified filter builder. Merges existing filter(s) with the new filter.

Parameters

  • type String Name of the filter type.
  • args ...args Arguments passed to filter builder.

Returns Bodybuilder Builder class.

query

Apply a query of a given type providing all the necessary arguments, passing these arguments directly to the specified query builder. Merges existing query(s) with the new query.

Parameters

  • type String Name of the query type.
  • args ...args Arguments passed to query builder.

Returns Bodybuilder Builder class.

aggregation

Apply a aggregation of a given type providing all the necessary arguments, passing these arguments directly to the specified aggregation builder. Merges existing aggregation(s) with the new aggregation. You may nest aggregations by passing in a Function callback as the last parameter. The callback will receive the newly built aggregation upon which you can keep calling aggregation(type, ...args).

Parameters

  • type String Name of the aggregation type.
  • args ...args Arguments passed to aggregation builder. May include am optional nesting function as its last element.

Examples

var body = new Bodybuilder()
  .query('match', 'text', 'this is a test')
  .aggregation('terms', 'someField', 'bySomeField',
    // Nest aggregations on "bySomeField"
    agg =>
      agg
        .agregation('max', 'someOtherField')
        .aggregation('missing', 'anotherField')
   )
  .build()

Returns Bodybuilder Builder class.

Filters

Construct elasticsearch filters.

Examples

var body = new Bodybuilder()
  .filter('missing', 'user', 'kimchy')
  .build()

existsFilter

Construct an Exists filter.

Parameters

  • field String Field name to check existence.

Returns Object Exists filter.

fuzzyFilter

Construct a Fuzzy filter.

Parameters

  • field String Field name to query over.
  • term String Query value.

Returns Object Fuzzy filter.

matchFilter

Construct a Match filter.

Parameters

  • field String Field name to query over.
  • term String Query value.

Returns Object Match filter.

geoBoundingBoxFilter

Construct a geo bounding box filter.

Parameters

  • field String Field name to query over.
  • location Object GeoHash, GeoJSON or Vertices

Returns Object Geo bounding box filter.

geoDistanceFilter

Construct a Geo distance filter.

Parameters

  • field String Field name to query over.
  • distance String Distance.
  • point Object Geo point coordinates (conform with GeoJSON).

Returns Object Geo distance filter.

geoShapeFilter

Construct a geo shape filter.

Parameters

  • field String Field name to query over.
  • shape Object GeoJSON for intersection.

Returns Object Geo shape filter.

idsFilter

Construct an Ids filter.

Parameters

Returns Object Ids filter.

matchAllFilter

Construct a Match All filter.

Returns Object Match All filter.

missingFilter

Construct a Missing filter.

Parameters

  • field String Field name to check if missing.

Returns Object Missing filter.

nestedFilter

Construct a Nested filter: a filter inside a filter.

See: elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-filter.html

Parameters

  • path String Name of the field containing the nested fields.
  • type String Name of the desired nested filter.
  • field String Name of the nested field.
  • args Array Remaining arguments used to construct nested filter.

Returns Object Nested filter.

prefixFilter

Construct a Prefix filter.

Parameters

  • field String Field name to query over.
  • prefixTerm String Query value.

Returns Object Prefix filter.

rangeFilter

Construct a Range filter.

Parameters

  • field String Field name to query over.
  • ranges Object One or more range queries.

Returns Object Range filter.

regexpFilter

Construct a Regexp filter.

Parameters

  • field String Field name to query over.
  • regexp String Query value.

Returns Object Regexp filter.

wildcardFilter

Construct a Wildcard filter.

Parameters

  • field String Field name to query over.
  • regexp String Query value.

Returns Object Wildcard filter.

termFilter

Construct a Term filter.

Parameters

  • field String Field name to query over.
  • term String Query value.

Returns Object Term filter.

termsFilter

Construct a Terms filter.

Parameters

  • field String Field name to query over.
  • terms Array Array of query terms.

Returns Object Terms filter.

typeFilter

Construct a Type filter.

Parameters

Returns Object Type filter.

Queries

Construct elasticsearch queries.

Examples

var body = new Bodybuilder()
  .query('query_string', 'this AND that')
  .build()

fuzzyQuery

Construct a Fuzzy query.

Parameters

  • field String Field name to query over.
  • term String Query value.

Returns Object Fuzzy query.

matchQuery

Construct a Match query.

Parameters

Returns Object Match query.

multiMatchQuery

Construct a Multi Match query. Default type is 'best_fields'.

Parameters

Returns Object Multi Match query.

queryStringQuery

Construct a Query String query.

Parameters

Returns Object Query String query.

rangeQuery

Construct a Range query.

Parameters

  • field String Field name to query over.
  • ranges Object One or more range queries.

Returns Object Range query.

termQuery

Construct a Term query.

Parameters

  • field String Field name to query over.
  • term String Query value.

Returns Object Term query.

termsQuery

Construct a Terms query.

Parameters

  • field String Field name to query over.
  • terms Array Array of query terms.

Returns Object Terms query.

functionScoreQuery

Construct a function_score query https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html

Parameters

  • functions Array Array of scoring function
  • opts [Object](default {}) Optional function_score fields

Returns Object Function score query

typeQuery

Construct a Type query.

Parameters

Returns Object Type query.

Aggregations

Construct elasticsearch aggregations.

Examples

var body = new Bodybuilder()
  .aggregation('sum', 'grade')
  .build()

avgAggregation

Construct a Avg aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_avg_.
  • opts Object Additional options to include in the aggregation.

Returns Object Avg Aggregation.

cardinalityAggregation

Construct a Cardinality aggregation

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_cardinality_.
  • opts Object Additional options to include in the aggregation.

Returns Object Cardinality Aggregation.

childrenAggregation

Construct a Children aggregation.

Parameters

  • type String Document type on which to join.
  • name String Aggregation name. Defaults to agg_histogram_.

Returns Object Children aggregation.

dateHistogramAggregation

Construct a Date Histogram aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_date_histogram_.
  • opts Object Additional options to include in the aggregation.

Returns Object Date Histogram Aggregation.

extendedStatsAggregation

Construct a Extended Stats aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_extended_stats_.
  • opts Object Additional options to include in the aggregation.

Returns Object Extended Stats Aggregation.

filterAggregation

Construct a Filter aggregation.

Parameters

  • filterCb String Callback function that will be passed the FilterBuilder
  • name String Aggregation name. Defaults to agg_filter.
  • opts Object Additional options to include in the aggregation.

Returns Object Filter Aggregation.

geohashAggregation

Construct a Geohash grid aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_histogram_.
  • opts Object Additional options to include in the aggregation.

Returns Object Histogram Aggregation.

globalAggregation

Construct a Global aggregation.

Parameters

  • name [String] Aggregation name. Defaults to agg_global.

Returns Object Global aggregation.

histogramAggregation

Construct a Histogram aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_histogram_.
  • opts Object Additional options to include in the aggregation.

Returns Object Histogram Aggregation.

maxAggregation

Construct a Max aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_max_.
  • opts Object Additional options to include in the aggregation.

Returns Object Max aggregation.

minAggregation

Construct a Min aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_min_.
  • opts Object Additional options to include in the aggregation.

Returns Object Min aggregation.

missingAggregation

Construct a Missing aggregation.

Parameters

  • field String Field name to aggregate over.
  • name String Aggregation name. Defaults to agg_missing_.

Returns Object Missing Aggregation.

nestedAggregation

Construct a Nested aggregation.

Parameters

  • path String Path of the nested documents.
  • name [String] Aggregation name. Defaults to agg_nested_.

Returns Object Nested aggregation.

percentilesAggregation

Construct a Percentiles aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_percentiles_.
  • opts Object Additional options to include in the aggregation.

Returns Object Percentiles Aggregation.

rangeAggregation

Construct a Range aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_terms_.
  • opts Object Additional options to include in the aggregation.

Returns Object Range aggregation.

reverseNestedAggregation

Construct a Reverse nested aggregation.

Parameters

  • name [String] Aggregation name. Defaults to agg_reverse_nested.
  • opts Object Additional options to include in the aggregation.

Returns Object Reverse nested aggregation.

scriptedMetricAggregation

Construct a Scripted Metric aggregation.

Parameters

  • map_script String The script as a string associated to the map_script step.
  • name [String] Aggregation name. Defaults to agg_scripted_metric.
  • opts Object Additional options to include in the aggregation.

Returns Object Scripted Metric aggregation.

significantTermsAggregation

Construct a Significant Terms aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_significant_terms_.
  • opts Object Additional options to include in the aggregation.

Returns Object Significant Terms aggregation.

statsAggregation

Construct a Stats aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_stats_.
  • opts Object Additional options to include in the aggregation.

Returns Object Stats Aggregation.

sumAggregation

Construct a Sum aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_sum_.
  • opts Object Additional options to include in the aggregation.

Returns Object Sum Aggregation.

termsAggregation

Construct a Terms aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_terms_.
  • opts Object Additional options to include in the aggregation.

Returns Object Terms aggregation.

topHitsAggregation

Construct a Top hits aggregation.

Parameters

  • name [String] Aggregation name. Defaults to 'agg_top_hits_{count}'.
  • opts Object Options to include in the aggregation.

Returns Object Top hits Aggregation.

valueCountAggregation

Construct a Value Count aggregation.

Parameters

  • field String Field name to aggregate over.
  • name [String] Aggregation name. Defaults to agg_value_count_.
  • opts Object Additional options to include in the aggregation.

Returns Object Value Count Aggregation.