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 = [])— top-level; use withasRaw()/asMatch()orMatch(field, query)matchPhrase(field, query, options = [])— nests itself as aboolmustclausemultiMatch(fields, query)— nests itself as aboolmustclause
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)
v2 behavior
Repeating any bool clause (mustMatch, shouldMatch, mustNot, …) appends to an array of clause objects, so chaining multiple clauses of the same type produces valid DSL. multiMatch and matchPhrase no longer require asRaw() — they switch to a bool context automatically.
Pagination and sorting
orderBy(field, direction = 'ASC')— throwsInvalidQueryon a direction other than asc/desctake(size)/limit(size)skip(from)/offset(from)simplePaginate(size = 15, from = 0)cursorPaginate(size = 15, sort = [])
Execution
all(perPage = 15, columns = ['*'])— bounded first page viamatch_allget(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 (results are read from the returned collection, e.g.$rooms->priceAvg())
Filters
filterByTerm(field, value)filterByRange(field, value, operator)or chainrange(field, operator, value)— operators:gt,gte,lt,lte- Geo:
filterByGeoShape,filterByGeoDistance,filterByGeoPolygon,filterByGeoDistanceRange,filterByGeoBoundingBox
v2 behavior
Filters are valid inside a bool query. If you add filters without an explicit asBoolean(), the builder now promotes the query into a bool and attaches the filters, instead of silently dropping them.
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)bulk(rows, chunkSize = null)— bulk index; returns aBulkResultupsert(rows, chunkSize = null)— bulk update-or-insert (each row needs anid); returns aBulkResult
Index targeting
from(index|array)— override the search index for this query (wildcard/comma allowed)into(index)— override the concrete write index for this call
Utilities
find(id|array)— returns a single bridge or a collectionwithValues(values, field = null, options = [])— for queries that acceptvalues