---
schema_version: "1"
id: a1fd72f02091c26c6e90dc58544b7bbcfb298e15aa2e7b9fb21d2fe6ae277593
title: data search
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforcedx/sfclireference/guides/data/cli_reference_data_search.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-cli-reference/guide/cli_reference_data_search.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: cbbed62e065f60d0015558e08c61807fa19560e9268a9509b9eb0fd387d163e5
products:
  - Salesforce CLI Command Reference
  - salesforcedx
---
<!-- prettier-ignore-start -->

# data search

Execute a SOSL text-based search query.

## Description for data search

Specify the SOSL query at the command line with the --query flag or read the query from a file with the --file flag.

By default, the results are written to the terminal in human-readable format. If you specify `--result-format csv`, the output is written to one or more CSV (comma-separated values) files. The file names correspond to the Salesforce objects in the results, such as Account.csv. Both `--result-format human` and `--result-format json` display only to the terminal.

## Flags

| Flag Name (Long) | Flag Name (Short) | Description |
|------------------|-------------------|-------------|
| <code>&#8209;&#8209;api&#8209;version</code> | N/A | **Type:** Value<br><br>Override the api version used for api requests made by this command |
| <code>&#8209;&#8209;file</code> | <code>&#8209;f</code> | **Type:** Value<br><br>File that contains the SOSL query. |
| <code>&#8209;&#8209;flags&#8209;dir</code> | N/A | **Type:** Value<br><br>Import flag values from a directory. |
| <code>&#8209;&#8209;json</code> | N/A | **Type:** Boolean<br><br>Format output as json. |
| <code>&#8209;&#8209;query</code> | <code>&#8209;q</code> | **Type:** Value<br><br>SOSL query to execute. |
| <code>&#8209;&#8209;result&#8209;format</code> | <code>&#8209;r</code> | **Type:** Value<br>**Valid Values:** `human`, `csv`, `json`<br>**Default value:** `human`<br><br>Format to display the results, or to write to disk if you specify "csv". |
| <code>&#8209;&#8209;target&#8209;org</code> | <code>&#8209;o</code> | **Type:** Value<br>**Required**<br><br>Username or alias of the target org. Not required if the `target-org` configuration variable is already set. |

## Examples for data search

Specify a SOSL query at the command line; the command uses your default org:

```shell
sf data search --query "FIND {Anna Jones} IN Name Fields RETURNING Contact (Name, Phone)"
```

Read the SOSL query from a file called "query.txt"; the command uses the org with alias "my-scratch":

```shell
sf data search --file query.txt --target-org my-scratch
```

Similar to the previous example, but write the results to one or more CSV files, depending on the Salesforce objects in the results:

```shell
sf data search --file query.txt --target-org my-scratch --result-format csv
```
<!-- prettier-ignore-end -->
