---
url: https://elasticbridge.dev/docs/v2/fulltext-search.md
---
# Full Text Search

ElasticBridge provides fluent methods for building full-text and related queries.

Notes

* All methods accept `field`, `query`, and optional `options` depending 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](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#match-field-params).

```php
return HotelRoom::query()
    ->asRaw()
    ->match(field: 'advertiser', query: 'hotel', options: [
        'fuzziness' => 'auto',
        'operator' => 'AND',
    ])
    ->get();
```

::: warning 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`.

```php
return HotelRoom::asRaw()
    ->orMatch('advertiser', 'hotel')
    ->get();
```

## Match Phrase

Searches for the exact sequence of words in a field. See valid [options](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html#match-phrase-field-params).

```php
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.

```php
return HotelRoom::multiMatch(
    field: ['advertiser', 'service_type'],
    query: 'hotel'
)->get();
```

::: tip 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:

```json
{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "hotel",
            "fields": ["advertiser", "service_type"]
          }
        }
      ]
    }
  }
}
```

:::

## Bool helpers

```php
// 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:

```php
HotelRoom::asBoolean()
    ->mustMatch('advertiser', 'booking.com')
    ->mustMatch('city', 'accra')
    ->get();
```

Unavailable in this version

* `match_phrase_prefix` and `match_bool_prefix` are not implemented at this time.
