Full Text Search
ElasticBridge provides fluent methods for building full-text and related queries.
Notes
- All methods accept
field,query, and optionaloptionsdepending on the query type. - Use
asBoolean()when combining queries with bool context (must/should/must_not).
Match
Returns documents that match a provided text, number, date or boolean value. See valid options.
return HotelRoom::query()
->asRaw()
->match(field: 'advertiser', query: 'hotel', options: [
'fuzziness' => 'auto',
'operator' => 'AND',
])
->get();Changed in v2
match is a top-level query — use it with asRaw() or asMatch(). Placing it directly in a bool context (e.g. asBoolean()->match(...)) now throws Lacasera\ElasticBridge\Exceptions\InvalidQuery, because bool only accepts must/should/must_not/filter. To match inside a bool query, use mustMatch() / shouldMatch().
Or Match
Convenience for a match with operator = or.
return HotelRoom::asRaw()
->orMatch('advertiser', 'hotel')
->get();Match Phrase
Searches for the exact sequence of words in a field. See valid options.
return HotelRoom::matchPhrase('title', 'new york hotel', [
'slop' => 1,
])->get();Multi Match
Builds on match to allow multi-field queries. The field parameter can be a string or an array of fields.
return HotelRoom::multiMatch(
field: ['advertiser', 'service_type'],
query: 'hotel'
)->get();Changed in v2
multiMatch() and matchPhrase() no longer need asRaw(). They have no term level of their own, so they now nest themselves as a bool must clause automatically, producing valid DSL that composes with other bool clauses:
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "hotel",
"fields": ["advertiser", "service_type"]
}
}
]
}
}
}Bool helpers
// must match within bool context
HotelRoom::asBoolean()
->mustMatch('advertiser', 'booking.com')
->get();
// match all within should or must contexts
HotelRoom::asRaw()->shouldMatchAll();
HotelRoom::asRaw()->matchAll();Chaining multiple clauses of the same type is fully supported and produces an array of clause objects:
HotelRoom::asBoolean()
->mustMatch('advertiser', 'booking.com')
->mustMatch('city', 'accra')
->get();Unavailable in this version
match_phrase_prefixandmatch_bool_prefixare not implemented at this time.