Skip to content

Commit f135998

Browse files
authored
[DOCS] Augment self-managed connector tutorials (#131127)
1 parent 6832ca4 commit f135998

File tree

5 files changed

+200
-228
lines changed

5 files changed

+200
-228
lines changed

docs/docset.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,6 @@ subs:
111111
feat-imp: "feature importance"
112112
feat-imp-cap: "Feature importance"
113113
nlp: "natural language processing"
114+
index-manage-app: "Index Management"
115+
connectors-app: "Connectors"
116+
ingest-pipelines-app: "Ingest Pipelines"

docs/reference/search-connectors/api-tutorial.md

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,31 @@ applies_to:
66
elasticsearch: ga
77
mapped_pages:
88
- https://www.elastic.co/guide/en/elasticsearch/reference/current/es-connectors-tutorial-api.html
9+
description: Use APIs to synchronize data from a PostgreSQL data source into Elasticsearch.
910
---
1011

1112
# Connector API tutorial [es-connectors-tutorial-api]
1213

13-
Learn how to set up a self-managed connector using the [{{es}} Connector APIs](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-connector).
14+
Learn how to set up a self-managed connector using the [{{es}} connector APIs]({{es-apis}}group/endpoint-connector).
1415

15-
For this example we’ll use the connectors-postgresql,PostgreSQL connector to sync data from a PostgreSQL database to {{es}}. We’ll spin up a simple PostgreSQL instance in Docker with some example data, create a connector, and sync the data to {{es}}. You can follow the same steps to set up a connector for another data source.
16+
For this example we’ll use the [PostgreSQL connector](/reference/search-connectors/es-connectors-postgresql.md) to sync data from a PostgreSQL database to {{es}}. We’ll spin up a simple PostgreSQL instance in Docker with some example data, create a connector, and sync the data to {{es}}. You can follow the same steps to set up a connector for another data source.
1617

1718
::::{tip}
18-
This tutorial focuses on running a self-managed connector on your own infrastructure, and managing syncs using the Connector APIs. See connectors for an overview of how connectors work.
19+
This tutorial focuses on running a self-managed connector on your own infrastructure, and managing syncs using the connector APIs.
1920

2021
If you’re just getting started with {{es}}, this tutorial might be a bit advanced. Refer to [quickstart](docs-content://solutions/search/get-started.md) for a more beginner-friendly introduction to {{es}}.
2122

22-
If you’re just getting started with connectors, you might want to start in the UI first. Check out this tutorial that focuses on managing connectors using the UI:
23-
24-
* [Self-managed connector tutorial](/reference/search-connectors/es-postgresql-connector-client-tutorial.md). Set up a self-managed PostgreSQL connector.
23+
If you’re just getting started with connectors, you might want to start in the UI first. Check out this tutorial that focuses on managing connectors using the UI: [](/reference/search-connectors/es-postgresql-connector-client-tutorial.md).
2524

2625
::::
2726

28-
29-
### Prerequisites [es-connectors-tutorial-api-prerequisites]
27+
## Prerequisites [es-connectors-tutorial-api-prerequisites]
3028

3129
* You should be familiar with how connectors, connectors work, to understand how the API calls relate to the overall connector setup.
3230
* You need to have [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed.
3331
* You need to have {{es}} running, and an API key to access it. Refer to the next section for details, if you don’t have an {{es}} deployment yet.
3432

35-
36-
### Set up {{es}} [es-connectors-tutorial-api-setup-es]
33+
## Set up {{es}} [es-connectors-tutorial-api-setup-es]
3734

3835
If you already have an {{es}} deployment on Elastic Cloud (*Hosted deployment* or *Serverless project*), you’re good to go. To spin up {{es}} in local dev mode in Docker for testing purposes, open the collapsible section below.
3936

@@ -73,7 +70,8 @@ Note: With {{es}} running locally, you will need to pass the username and passwo
7370

7471

7572
::::{admonition} Running API calls
76-
You can run API calls using the [Dev Tools Console](docs-content://explore-analyze/query-filter/tools/console.md) in Kibana, using `curl` in your terminal, or with our programming language clients. Our example widget allows you to copy code examples in both Dev Tools Console syntax and curl syntax. To use curl, you’ll need to add authentication headers to your request.
73+
You can run API calls using the [Dev Tools Console](docs-content://explore-analyze/query-filter/tools/console.md) in Kibana, using `curl` in your terminal, or with our programming language clients.
74+
To use curl, you’ll need to add authentication headers to your request.
7775

7876
Here’s an example of how to do that. Note that if you want the connector ID to be auto-generated, use the `POST _connector` endpoint.
7977

@@ -88,13 +86,11 @@ curl -s -X PUT http://localhost:9200/_connector/my-connector-id \
8886
}'
8987
```
9088

91-
Refer to connectors-tutorial-api-create-api-key for instructions on creating an API key.
89+
Refer to [](/reference/search-connectors/es-postgresql-connector-client-tutorial.md) for instructions on creating an API key.
9290

9391
::::
9492

95-
96-
97-
### Run PostgreSQL instance in Docker (optional) [es-connectors-tutorial-api-setup-postgres]
93+
## Run PostgreSQL instance in Docker (optional) [es-connectors-tutorial-api-setup-postgres]
9894

9995
For this tutorial, we’ll set up a PostgreSQL instance in Docker with some example data. Of course, you can **skip this step and use your own existing PostgreSQL instance** if you have one. Keep in mind that using a different instance might require adjustments to the connector configuration described in the next steps.
10096

@@ -105,7 +101,7 @@ Let’s launch a PostgreSQL container with a user and password, exposed at port
105101
docker run --name postgres -e POSTGRES_USER=myuser -e POSTGRES_PASSWORD=mypassword -p 5432:5432 -d postgres
106102
```
107103

108-
**Download and import example data**
104+
### Download and import example data
109105

110106
Next we need to create a directory to store our example dataset for this tutorial. In your terminal, run the following command:
111107

@@ -145,10 +141,9 @@ This tutorial uses a very basic setup. To use advanced functionality such as fil
145141

146142
Now it’s time for the real fun! We’ll set up a connector to create a searchable mirror of our PostgreSQL data in {{es}}.
147143

144+
## Create a connector [es-connectors-tutorial-api-create-connector]
148145

149-
### Create a connector [es-connectors-tutorial-api-create-connector]
150-
151-
We’ll use the [Create connector API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-connector-put) to create a PostgreSQL connector instance.
146+
We’ll use the [create connector API]({{es-apis}}operation/operation-connector-put) to create a PostgreSQL connector instance.
152147

153148
Run the following API call, using the [Dev Tools Console](docs-content://explore-analyze/query-filter/tools/console.md) or `curl`:
154149

@@ -171,10 +166,9 @@ Note that we specified the `my-connector-id` ID as a part of the `PUT` request.
171166

172167
If you’d prefer to use an autogenerated ID, replace `PUT _connector/my-connector-id` with `POST _connector`.
173168

169+
## Set up the connector service [es-connectors-tutorial-api-deploy-connector]
174170

175-
### Run connector service [es-connectors-tutorial-api-deploy-connector]
176-
177-
Now we’ll run the connector service so we can start syncing data from our PostgreSQL instance to {{es}}. We’ll use the steps outlined in connectors-run-from-docker.
171+
Now we’ll run the connector service so we can start syncing data from our PostgreSQL instance to {{es}}. We’ll use the steps outlined in [](/reference/search-connectors/es-connectors-run-from-docker.md).
178172

179173
When running the connectors service on your own infrastructure, you need to provide a configuration file with the following details:
180174

@@ -183,10 +177,9 @@ When running the connectors service on your own infrastructure, you need to prov
183177
* Your third-party data source type (`service_type`)
184178
* Your connector ID (`connector_id`)
185179

180+
### Create an API key [es-connectors-tutorial-api-create-api-key]
186181

187-
#### Create an API key [es-connectors-tutorial-api-create-api-key]
188-
189-
If you haven’t already created an API key to access {{es}}, you can use the [_security/api_key](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-create-api-key) endpoint.
182+
If you haven’t already created an API key to access {{es}}, you can use the [_security/api_key]({{es-apis}}operation/operation-security-create-api-key) endpoint.
190183

191184
Here, we assume your target {{es}} index name is `music`. If you use a different index name, adjust the request body accordingly.
192185

@@ -225,9 +218,7 @@ You can also create an API key in the {{kib}} and Serverless UIs.
225218

226219
::::
227220

228-
229-
230-
#### Prepare the configuration file [es-connectors-tutorial-api-prepare-configuration-file]
221+
### Prepare the configuration file [es-connectors-tutorial-api-prepare-configuration-file]
231222

232223
Let’s create a directory and a `config.yml` file to store the connector configuration:
233224

@@ -249,8 +240,7 @@ connectors:
249240
250241
We provide an [example configuration file](https://raw.githubusercontent.com/elastic/connectors/main/config.yml.example) in the `elastic/connectors` repository for reference.
251242

252-
253-
#### Run the connector service [es-connectors-tutorial-api-run-connector-service]
243+
### Run the service [es-connectors-tutorial-api-run-connector-service]
254244

255245
Now that we have the configuration file set up, we can run the connector service locally. This will point your connector instance at your {{es}} deployment.
256246

@@ -273,12 +263,11 @@ Verify your connector is connected by getting the connector status (should be `n
273263
GET _connector/my-connector-id
274264
```
275265

276-
277-
### Configure connector [es-connectors-tutorial-api-update-connector-configuration]
266+
## Configure the connector [es-connectors-tutorial-api-update-connector-configuration]
278267

279268
Now our connector instance is up and running, but it doesn’t yet know *where* to sync data from. The final piece of the puzzle is to configure our connector with details about our PostgreSQL instance. When setting up a connector in the Elastic Cloud or Serverless UIs, you’re prompted to add these details in the user interface.
280269

281-
But because this tutorial is all about working with connectors *programmatically*, we’ll use the [Update connector configuration API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-connector-update-configuration) to add our configuration details.
270+
But because this tutorial is all about working with connectors *programmatically*, we’ll use the [update connector configuration API]({{es-apis}}operation/operation-connector-update-configuration) to add our configuration details.
282271

283272
::::{tip}
284273
Before configuring the connector, ensure that the configuration schema is registered by the service. For self-managed connectors, the schema registers on service startup (once the `config.yml` is populated).
@@ -310,9 +299,7 @@ Configuration details are specific to the connector type. The keys and values wi
310299

311300
::::
312301

313-
314-
315-
### Sync data [es-connectors-tutorial-api-sync]
302+
## Sync your data [es-connectors-tutorial-api-sync]
316303

317304
We’re now ready to sync our PostgreSQL data to {{es}}. Run the following API call to start a full sync job:
318305

@@ -327,15 +314,13 @@ POST _connector/_sync_job
327314
To store data in {{es}}, the connector needs to create an index. When we created the connector, we specified the `music` index. The connector will create and configure this {{es}} index before launching the sync job.
328315

329316
::::{tip}
330-
In the approach we’ve used here, the connector will use [dynamic mappings](docs-content://manage-data/data-store/mapping.md#mapping-dynamic) to automatically infer the data types of your fields. In a real-world scenario you would use the {{es}} [Create index API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-create) to first create the index with the desired field mappings and index settings. Defining your own mappings upfront gives you more control over how your data is indexed.
317+
In the approach we’ve used here, the connector will use [dynamic mappings](docs-content://manage-data/data-store/mapping.md#mapping-dynamic) to automatically infer the data types of your fields. In a real-world scenario you would use the {{es}} [create index API]({{es-apis}}operation/operation-indices-create) to first create the index with the desired field mappings and index settings. Defining your own mappings upfront gives you more control over how your data is indexed.
331318

332319
::::
333320

321+
### Check sync status [es-connectors-tutorial-api-check-sync-status]
334322

335-
336-
#### Check sync status [es-connectors-tutorial-api-check-sync-status]
337-
338-
Use the [Get sync job API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-connector-sync-job-get) to track the status and progress of the sync job. By default, the most recent job statuses are returned first. Run the following API call to check the status of the sync job:
323+
Use the [get sync job API]({{es-apis}}operation/operation-connector-sync-job-get) to track the status and progress of the sync job. By default, the most recent job statuses are returned first. Run the following API call to check the status of the sync job:
339324

340325
```console
341326
GET _connector/_sync_job?connector_id=my-connector-id&size=1
@@ -345,6 +330,8 @@ The job document will be updated as the sync progresses, you can check it as oft
345330

346331
Once the job completes, the status should be `completed` and `indexed_document_count` should be **622**.
347332

333+
## Query your data
334+
348335
Verify that data is present in the `music` index with the following API call:
349336

350337
```console
@@ -357,8 +344,7 @@ GET music/_count
357344
GET music/_search
358345
```
359346

360-
361-
## Troubleshooting [es-connectors-tutorial-api-troubleshooting]
347+
## Troubleshoot [es-connectors-tutorial-api-troubleshooting]
362348

363349
Use the following command to inspect the latest sync job’s status:
364350

@@ -369,7 +355,7 @@ GET _connector/_sync_job?connector_id=my-connector-id&size=1
369355
If the connector encountered any errors during the sync, you’ll find these in the `error` field.
370356

371357

372-
### Cleaning up [es-connectors-tutorial-api-cleanup]
358+
## Clean up [es-connectors-tutorial-api-cleanup]
373359

374360
To delete the connector and its associated sync jobs run this command:
375361

@@ -397,13 +383,12 @@ docker stop <container_id>
397383
docker rm <container_id>
398384
```
399385

386+
## Next steps [es-connectors-tutorial-api-next-steps]
400387

401-
### Next steps [es-connectors-tutorial-api-next-steps]
402-
403-
Congratulations! You’ve successfully set up a self-managed connector using the Connector APIs.
388+
Congratulations! You’ve successfully set up a self-managed connector using the connector APIs.
404389

405390
Here are some next steps to explore:
406391

407-
* Learn more about the [Connector APIs](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-connector).
392+
* Learn more about the [connector APIs]({{es-apis}}group/endpoint-connector).
408393
* Learn how to deploy {{es}}, {{kib}}, and the connectors service using Docker Compose in our [quickstart guide](https://github.com/elastic/connectors/tree/main/scripts/stack#readme).
409394

0 commit comments

Comments
 (0)