
## Full text queries

URL: https://docs.atlan.com/product/capabilities/build-apps/sdks/python/search/references/queries/full-text

> Use full-text queries with the Atlan Python SDK (pyatlan) to search analyzed text fields and find results by keywords.

# Full text queries

Full text queries allow you to find results based on analyzed text fields.[^1] For example, by a word or phrase within a longer description.

Unlike [term-level queries](https://docs.atlan.com/llms/platform/python/term-level/llms.txt), the search terms you use in a full-text query *are* analyzed. This means what you search for is tokenized first (broken up into separate words), singular / plural variants determined, synonyms applied, and so on.

> *Details — see full content on the documentation site.*

## Match

[Match queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html) return results where the asset's value for that attribute matches some part of what you're searching.

### Java

```java showLineNumbers title="Build the query and request"
IndexSearchRequest index = client.assets.select() // (1)
 .where(Asset.NAME.match("tmp")) // (1)
 .toRequest();
```

1. You can search across all assets using the `select()` method of the `assets` member on any client.
2. Chain a `where()` onto the select, with the static constant representing a field of the type you want to search to start a query, in this case the `NAME` of an `Asset`. Adding the `match()` predicate creates a match query.

 ```java title="Equivalent query through Elastic"
 Query byMatch = MatchQuery.of(m -> m
 .field("name")
 .query("tmp")
 ._toQuery();
 ```

### Python

```python showLineNumbers title="Build the query"
from pyatlan.model.assets import Asset
from pyatlan.model.fluent_search import FluentSearch

index = (FluentSearch() # (1)
 .where(Asset.NAME.match("tmp")) # (2)
 ).to_request()
```

1. You can search across all assets using a `FluentSearch()` object.
2. Use the class variable representing a field of the type you want to search to start a query, in this case the `NAME` of an `Asset`. Adding the `match()` predicate creates a match query.

### Kotlin

```kotlin showLineNumbers title="Build the query and request"
val index = client.assets.select() // (1)
 .where(Asset.NAME.match("tmp")) // (1)
 .toRequest()
```

1. You can search across all assets using the `select()` method of the `assets` member on any client.
2. Chain a `where()` onto the select, with the static constant representing a field of the type you want to search to start a query, in this case the `NAME` of an `Asset`. Adding the `match()` predicate creates a match query.

 ```kotlin title="Equivalent query through Elastic"
 val byMatch = MatchQuery.of(m -> m
 .field("name")
 .query("tmp")
 ._toQuery()
 ```

### Raw REST API

```json showLineNumbers title="POST /api/meta/search/indexsearch"
{
 "dsl": { // (1)
 "query": { // (2)
 "match": { // (3)
 "name": { // (4)
 "query": "tmp" // (5)
 }
 }
 }
 }
}
```

1. Queries must be within the `dsl` object in the API...
2. ...and within that the `query` object.
3. For a match query, there needs to be a `match` object embedded within the `query` object.
4. Within this object should be a key with the name of the Elasticsearch field (Atlan attribute) to match against.
5. The value for this field (attribute) to match against should be given through the `query` property.

## Match phrase

Unlike a regular [`match`](https://docs.atlan.com/llms/platform/python/full-text/llms.txt) query, which performs a full-text search and may return results with individual words appearing in any order, a `match_phrase` query ensures that the terms appear in the exact order specified.

For example, to search for assets where the `description` field contains the exact phrase `"data pipeline"`:

### Java

:::warning[Coming soon]
:::

### Python

```python showLineNumbers title="Build the query"
from pyatlan.model.assets import Asset
from pyatlan.model.fluent_search import FluentSearch

index = (
 FluentSearch() # (1)
 .where(Asset.DESCRIPTION.match_phrase("data pipeline")) # (2)
).to_request()
```

1. You can search across all assets using a `FluentSearch()` object.
2. Use the class variable representing a field of the type you want to search to start a query, in this case the `DESCRIPTION` of an `Asset`. Adding the `match_phrase()` predicate creates a match phrase query.

### Kotlin

:::warning[Coming soon]
:::

### Raw REST API

```json showLineNumbers title="POST /api/meta/search/indexsearch"
{
 "dsl": { // (1)
 "query": { // (2)
 "match_phrase": { // (3)
 "description": { // (4)
 "query": "data pipeline" // (5)
 }
 }
 }
 }
}
```

1. Queries must be within the `dsl` object in the API...
2. ...and within that the `query` object.
3. For a match phrase query, there needs to be a `match_phrase` object embedded within the `query` object.
4. Within this object should be a key with the name of the Elasticsearch field (Atlan attribute) to match against.
5. The value for this field (attribute) to match against should be given through the `query` property.

[^1]: This page is a summary of the details in the Elasticsearch Guide's [Full text queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html)

---
