> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lambdadb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Boolean query

> Combine multiple sub-queries in LambdaDB using boolean logic with filter, must, must_not, and should clauses. Supports boost scoring for relevance.

A query that matches documents based on boolean combinations of other queries.
The boolean query maps to [Lucene BooleanQuery](https://lucene.apache.org/core/10_4_0/core/org/apache/lucene/search/BooleanQuery.html).

## Boolean query array parameters

When used within a bool query array, each object can contain:

| Parameter | Description | Type | Required | Default |
| :- | :- | :- | :- | :- |
| `queryString`, `knn`, `sparseVector`, or `bool` | One query-type key directly on the clause; do not add a `query` wrapper | object or array | ✓ | |
| occur | Boolean occurrence type | string | | should |
| boost | Score multiplier for relevance | float | | 1.0 |

It is built using one or more boolean clauses, each clause with a typed occurrence. The occurrence types are:

### Occur

| Occur | Description |
| :- | :- |
| filter | The clause (query) must appear in matching documents. However, unlike `must`, the score of the query will be ignored. Each query defined under a `filter` acts as a logical "AND", returning only documents that match all the specified queries. |
| must | The clause (query) must appear in matching documents and will contribute to the score. Each query defined under a `must` acts as a logical "AND", returning only documents that match all the specified queries. |
| must\_not | The clause (query) must not appear in the matching documents. Each query defined under a `must_not` acts as a logical "NOT", returning only documents that do not match any of the specified queries. |
| should | With no `must` or `filter` clauses, at least one `should` clause must match. With a `must` or `filter` clause, `should` clauses are optional and contribute to the score when they match. |

For example, two `should` clauses match documents satisfying either clause. Adding a `filter` changes that behavior: the filter determines which documents can match, and the `should` clauses only affect their scores. Use `must` when a clause must match even alongside a filter. These rules apply independently at each nested `bool` level.

### Boost

Boost values that are less than 1.0 will give less importance to this query compared to other ones
while values that are greater than 1.0 will give more importance to the scores returned by this query.

## Examples

The examples are query objects. Place them under the request body's top-level `query`, alongside `size` and other [search options](https://docs.lambdadb.ai/guides/search/search-overview.md). A filter-only boolean query cannot use [native reranking](https://docs.lambdadb.ai/guides/search/native-reranking.md#query-restrictions).

### Boolean query with occur

```json theme={null}
{
  "bool": [
    {
      "queryString": {
        "query": "node_type:NODE"
      },
      "occur" : "filter"
    },
    {
      "queryString": {
        "query": "content:LambdaDB"
      },
      "occur" : "should"
    }
  ]
}
```

The `filter` requires `node_type:NODE`. The optional `should` clause boosts matching `content:LambdaDB` documents; it does not require every returned document to contain that term. Use `occur: "must"` for that clause if both conditions must match.

### Boolean query with boost

> [!NOTE]
>
> The boost value must be greater than zero.

```json theme={null}
{
  "bool": [
    {
      "queryString": {
        "query": "node_type:NODE"
      },
      "boost": 0.8
    },
    {
      "queryString": {
        "query": "content:LambdaDB"
      },
      "boost": 0.2
    }
  ]
}
```

The final score of the matched document is calculated as proportional to the boost values.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.