Query Builder Reference
Below are commonly used methods available on the bridge builder. Chain them fluently from your bridge class.
Term selection
asBoolean()— sets a bool query contextasRaw()— allows passing a raw body viaraw([...])asMatch(),asFuzzy(),asIds(),asPrefix(),asRange(),asRegex(),asTerm(),asTerms(),asTermSet(),asWildCard()
Full-text helpers
match(field, query, options = [])orMatch(field, query)matchPhrase(field, query, options = [])multiMatch(fields, query)
Bool helpers
shouldMatchAll(boost = 1.0)matchAll(boost = 1.0)mustMatch(field, value)must(query, field, value)mustNot(query, field, payload)mustExist(field)/shouldExist(field)
Pagination and sorting
orderBy(field, direction = 'ASC')take(size)/limit(size)skip(from)/offset(from)simplePaginate(size = 15, from = 0)cursorPaginate(size = 15, sort = [])
Execution
get(columns = ['*'])count()toQuery(asJson = false)— returns the built body as array or JSON
Aggregations
avg(field),min(field),max(field),sum(field)stats(field)returns a Stats objecthistogram(field, interval)returns bucketswithAggregate(type, field, options = [])to attach to a query
Filters
filterByTerm(field, value)filterByRange(field, value, operator)or chainrange(field, operator, value)- Geo:
filterByGeoShape,filterByGeoDistance,filterByGeoPolygon,filterByGeoDistanceRange,filterByGeoBoundingBox
Indexing and updates
create(attributes)— returns created_id(string)save()— updates existing or creates if missing (boolean)increment(field, counter = 1)/decrement(field, counter = 1)
Utilities
find(id|array)— returns a single bridge or a collectionwithValues(values, field = null, options = [])— for queries that acceptvalues