# 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                                                                                                                                                               |
| ----------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--api-version`   | N/A               | **Type:** Value<br><br>Override the api version used for api requests made by this command                                                                                |
| `--file`          | `-f`              | **Type:** Value<br><br>File that contains the SOSL query.                                                                                                                 |
| `--flags-dir`     | N/A               | **Type:** Value<br><br>Import flag values from a directory.                                                                                                               |
| `--json`          | N/A               | **Type:** Boolean<br><br>Format output as json.                                                                                                                           |
| `--query`         | `-q`              | **Type:** Value<br><br>SOSL query to execute.                                                                                                                             |
| `--result-format` | `-r`              | **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". |
| `--target-org`    | `-o`              | **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
```
