Loading

Elastic Microsoft SQL connector reference

The Elastic Microsoft SQL connector is a connector for Microsoft SQL databases. This connector is written in Python using the Elastic connector framework.

View the source code for this connector (branch main, compatible with Elastic 9.0).

Important

As of Elastic 9.0, managed connectors on Elastic Cloud Hosted are no longer available. All connectors must be self-managed.

This connector is available as a self-managed connector. To use this connector, satisfy all self-managed connector requirements.

To create a new Microsoft SQL connector:

  1. In the Kibana UI, navigate to the Search → Content → Connectors page from the main menu, or use the global search field.
  2. Follow the instructions to create a new Microsoft SQL self-managed connector.

You can use the Elasticsearch Create connector API to create a new self-managed Microsoft SQL self-managed connector.

For example:

 PUT _connector/my-mssql-connector {
  "index_name": "my-elasticsearch-index",
  "name": "Content synced from Microsoft SQL",
  "service_type": "mssql"
}

Refer to the Elasticsearch API documentation for details of all available Connector APIs.

Users require the sysadmin server role. Note that SQL Server Authentication is required. Windows Authentication is not supported.

To use this connector as a self-managed connector, see Self-managed connectors For additional usage operations, see Connectors UI in Kibana.

The following are compatible with Elastic connector frameworks:

  • Microsoft SQL Server versions 2017, 2019
  • Azure SQL
  • Amazon RDS for SQL Server

The following configuration fields are required to set up the connector:

host

The server host address where the Microsoft SQL Server is hosted. Default value is 127.0.0.1. Examples:

  • 192.158.1.38
  • demo.instance.demo-region.demo.service.com
port
The port where the Microsoft SQL Server is hosted. Default value is 9090.
username
The username of the account for Microsoft SQL Server. (SQL Server Authentication only)
password
The password of the account to be used for the Microsoft SQL Server. (SQL Server Authentication only)
database

Name of the Microsoft SQL Server database. Examples:

  • employee_database
  • customer_database
tables

Comma-separated list of tables. The Microsoft SQL connector will fetch data from all tables present in the configured database, if the value is * . Default value is *. Examples:

  • table_1, table_2
  • *

This field can be bypassed by advanced sync rules.

fetch_size
Rows fetched per request.
retry_count
The number of retry attempts per failed request.
schema

Name of the Microsoft SQL Server schema. Default value is dbo.

Examples:

  • dbo
  • custom_schema
ssl_enabled
SSL verification enablement. Default value is False.
ssl_ca

Content of SSL certificate. If SSL is disabled, the ssl_ca value will be ignored.

validate_host
Host validation enablement. Default value is False.

You can deploy the Microsoft SQL connector as a self-managed connector using Docker. Follow these instructions.

Refer to DOCKER.md in the elastic/connectors repo for more details.

Find all available Docker images in the official registry.

Tip

We also have a quickstart self-managed option using Docker Compose, so you can spin up all required services at once: Elasticsearch, Kibana, and the connectors service. Refer to this README in the elastic/connectors repo for more information.

  • Tables with no primary key defined are skipped.
  • If the last_user_update of sys.dm_db_index_usage_stats table is not available for a specific table and database then all data in that table will be synced.
Note
  • Files bigger than 10 MB won’t be extracted.
  • Permissions are not synced. All documents indexed to an Elastic deployment will be visible to all users with access to that Elastic Deployment.

Basic sync rules are identical for all connectors and are available by default. For more information read sync rules.

This connector supports advanced sync rules for remote filtering. These rules cover complex query-and-filter scenarios that cannot be expressed with basic sync rules. Advanced sync rules are defined through a source-specific DSL JSON snippet.

Note

A full sync is required for advanced sync rules to take effect.

Here are a few examples of advanced sync rules for this connector.


Example: Two queries

These rules fetch all records from both the employee and customer tables. The data from these tables will be synced separately to Elasticsearch.

[
  {
    "tables": [
      "employee"
    ],
    "query": "SELECT * FROM employee"
  },
  {
    "tables": [
      "customer"
    ],
    "query": "SELECT * FROM customer"
  }
]


Example: One WHERE query

This rule fetches only the records from the employee table where the emp_id is greater than 5. Only these filtered records will be synced to Elasticsearch.

[
  {
    "tables": ["employee"],
    "query": "SELECT * FROM employee WHERE emp_id > 5"
  }
]


Example: One JOIN query

This rule fetches records by performing an INNER JOIN between the employee and customer tables on the condition that the emp_id in employee matches the c_id in customer. The result of this combined data will be synced to Elasticsearch.

[
  {
    "tables": ["employee", "customer"],
    "query": "SELECT * FROM employee INNER JOIN customer ON employee.emp_id = customer.c_id"
  }
]
Warning

When using advanced rules, a query can bypass the configuration field tables. This will happen if the query specifies a table that doesn’t appear in the configuration. This can also happen if the configuration specifies * to fetch all tables while the advanced sync rule requests for only a subset of tables.

The connector framework enables operators to run functional tests against a real data source. Refer to Connector testing for more details.

To perform E2E testing for the Microsoft SQL connector, run the following command:

make ftest NAME=mssql

For faster tests, add the DATA_SIZE=small flag:

make ftest NAME=mssql DATA_SIZE=small

There are no known issues for this connector. See Known issues for any issues affecting all connectors.

See Troubleshooting.

See Security.

This connector uses the generic database connector source code (branch main, compatible with Elastic 9.0).

View additional code specific to this data source (branch main, compatible with Elastic 9.0).