Skip to content

Connect SPSync to Elasticsearch

SPSync writes one Elasticsearch index per table: a list’s main table, each multi-value child table and the shared users table. Rows are indexed by key, and a row deleted in SharePoint is removed from the index rather than flagged. This guide covers a cluster you run yourself and Elastic Cloud.

  • An Elasticsearch cluster you can reach over HTTP(S), and its URL, for example https://my-cluster.es.example.com:9200.
  • A user who can create roles, users or API keys on the cluster (the superuser role, or Kibana access with the right privileges).
  • Nothing to install on the machine that runs SPSync. SPSync keeps a small local state file (a DuckDB file) that records what it last sent, so it sends only the rows that changed. Keep that file on a disk that survives restarts.

Create the database and a least-privilege user

Section titled “Create the database and a least-privilege user”

SPSync needs to create indexes, add fields to them, write and delete documents and read them back. It needs nothing at cluster level beyond a reachable endpoint. This request is from the Elasticsearch documentation and has not been run here against a test cluster. In Kibana Dev Tools, or with curl, create a role:

PUT _security/role/spsync_loader
{
"indices": [
{
"names": ["dev_*", "sp_users"],
"privileges": ["create_index", "write", "read", "view_index_metadata", "manage"]
}
]
}

dev_* is the --prefix you give SPSync: every index is named from that prefix and the list name. Use your own prefix. After the first sync, list the indexes (GET _cat/indices) and tighten the pattern if you want to. manage is what lets SPSync add a field to an index that already exists when a SharePoint column is added. When a column changes type, Elasticsearch cannot change the field in place, so SPSync starts a new index with _v2 on the end and writes there from then on. The pattern dev_* already covers it.

Then make an API key from that role (recommended) or a user:

POST _security/api_key
{
"name": "spsync",
"role_descriptors": {
"spsync_loader": {
"indices": [
{
"names": ["dev_*", "sp_users"],
"privileges": ["create_index", "write", "read", "view_index_metadata", "manage"]
}
]
}
}
}

The response carries an encoded value. That is the key SPSync needs. It is shown once.

Rather than copying the requests above, spsync search-grants prints them for your prefix, with an expiry on the key, and runs nothing:

Terminal window
spsync search-grants --store elasticsearch --prefix dev_ --expires-in 90d

An API key with an expiration stops working by itself. Create the next key before the date and swap it in. This is from the Elasticsearch documentation and has not been run against a live cluster.

Elasticsearch listens on TCP 9200 for HTTP unless you changed it. On the desktop app and a self-hosted server the connection starts from that machine, so allow that machine’s address. For the Azure managed application, allow the address it connects out from.

  • Self-hosted: allow the SPSync address in the host firewall and in any load balancer in front of the cluster.
  • Elastic Cloud: under Security, Traffic filters, add the address as an IP filter, or use a private link filter and run SPSync inside that network. Without a filter the deployment is open to the internet, protected only by the key.
  • Elastic Cloud on Kubernetes and other managed hosts: allow the address on whichever ingress or security group fronts port 9200 or 443.

Use an https:// URL. SPSync verifies the server’s certificate unless you turn that off, and a URL that starts with http:// sends the key in clear text, so keep it to a closed test network.

A cluster whose certificate comes from a public authority, Elastic Cloud’s included, needs nothing more. For a self-signed certificate or a corporate CA, give SPSync the CA certificate as PEM text (the file whose first line is -----BEGIN CERTIFICATE-----). It replaces the machine’s trust store for this destination only.

On the Destination screen, paste the PEM into CA certificate bundle. A client certificate for mutual TLS goes in Client certificate and Client private key (an unencrypted PEM key). SPSync keeps these as stored secrets: in the operating system keychain on the desktop app, and as a Key Vault reference in the Azure edition, and it never shows them again after you save. If you reach the cluster by an address its certificate does not name, such as an IP address behind a load balancer, put the name the certificate does carry in Certificate name to check.

Clearing Verify the server certificate turns checking off. The connection stays encrypted but SPSync no longer checks who it is talking to. Use it only while you fix the certificate. SPSync logs a destination_tls_verification_disabled warning on every run, Test connection reports “connected (warning: …)” and spsync doctor prints a WARNING.

This setting is a preview. SPSync’s automated tests run the real Elasticsearch client against a real Elasticsearch container, serving a certificate from a throw-away CA, and check that the connection succeeds with the CA and fails without it. It has not been run against Elastic Cloud or a production cluster. spsync doctor prints a destination-tls line with the trust mode and, where a plain TLS handshake can read it, the server certificate’s subject and expiry date.

Either an Elasticsearch API key, or a user name and password (HTTP basic). Use exactly one. Elasticsearch service account tokens and single sign-on are not supported. An API key is better: it can be limited to the role above and revoked without touching a user.

For Elastic Cloud you can give the deployment’s Cloud ID (from the deployment’s overview page) instead of the URL. SPSync derives the endpoint from it. Set the URL or the Cloud ID, never both.

  • Desktop app: open the Destination screen, choose Elasticsearch, enter the Elasticsearch URL and either the API key or the username and password, then choose Test connection. SPSync manages the local state file itself. For Elastic Cloud, enter the Elastic Cloud ID and leave the URL empty. For a private CA, see Encrypt the connection.

  • CLI: the config names environment variables, never the key itself. SPSYNC_ES_STATE_PATH holds the path of the local state file, not a network address.

    Terminal window
    export SPSYNC_ES_STATE_PATH=/var/lib/spsync/elasticsearch-state.duckdb
    export SPSYNC_ES_API_KEY='<encoded key from the response above>'
    spsync export-config --output replication.yaml \
    --site-url https://contoso.sharepoint.com/sites/x --list Projects \
    --pipeline-name spsync_dev --prefix dev \
    --destination-kind elasticsearch --connection-string-env SPSYNC_ES_STATE_PATH \
    --dataset-name main \
    --elasticsearch-url https://my-cluster.es.example.com:9200 \
    --elasticsearch-api-key-env SPSYNC_ES_API_KEY \
    --client-id <entra-app-client-id>

    For basic auth, replace the last key flag with --elasticsearch-username spsync_loader --elasticsearch-password-env SPSYNC_ES_PASSWORD.

    The TLS settings and the Cloud ID are fields of the destination: block in the YAML file. Each certificate field names an environment variable, or a file: or env: reference:

    destination:
    kind: elasticsearch
    # ... as exported above
    tls_ca_env: SPSYNC_ES_CA # the PEM text, or file:/etc/spsync/es-ca.pem
    tls_client_cert_env: SPSYNC_ES_CLIENT_CERT # optional, with tls_client_key_env
    tls_client_key_env: SPSYNC_ES_CLIENT_KEY
    tls_server_name: es.internal # optional
    tls_verify: true # false turns checking off and warns on every run
    # elasticsearch_cloud_id: "name:abc..." # instead of elasticsearch_url
  • AI assistant: with the admin MCP server connected, ask for the destination requirements, then let the assistant create the destination with the URL. You enter the API key (or the password, if you set a user name) on the secure entry page, never in the chat.

Both ask the cluster for its basic information (the same request as opening the cluster URL in a browser). A pass means the URL is reachable, the certificate is trusted and the cluster accepted the key or the password. It does not prove the key can create or write to an index. The first sync is the real test of the privileges. spsync doctor reports the probe as destination-connectivity.

spsync doctor also asks the cluster who it connected as and appends it to that line, for example as API key 'spsync-writer' (user svc). If the key has an expiry date and it is within 14 days, or already past, the line adds a WARNING: key expires in N day(s), rotate it. The key value itself is never printed. If the key is not allowed to look up its own details, the identity or the expiry is simply left out and the check still passes.

Each run also writes one destination.connected_as line to the run log with the same identity, including the expiry warning when the key is close to expiring, so an operator can see in the log which key the load used. If the lookup fails the line is left out and the run is not affected.

What you see What it means and the fix
Connection refused or a timeout A firewall, security group or traffic filter is blocking the port, or the URL is wrong.
TLS certificate problem; server certificate verified against the system trust store The certificate is self-signed or from a private CA. Paste the CA into CA certificate bundle, or use a certificate from a public authority.
TLS certificate problem; ... certificate name checked as ... The certificate does not name the host you connect to. Correct Certificate name to check, or connect by a name the certificate carries.
Authentication failed: the API key or the password is incorrect The cluster answered with HTTP 401. The key is wrong, expired or revoked, or the user name or password is wrong. Check that you used the encoded value for a key. For the command line, fix the environment variable named in the config and run spsync doctor again.
401 security_exception or AuthenticationException The same problem as above, seen in a cluster log or a client other than SPSync.
403 security_exception ... is unauthorized for The key’s role does not cover the index. Widen the names pattern to match your prefix.
could not ping Elasticsearch cluster The cluster did not answer the request for any reason other than a rejected key or password: it is not healthy, the URL or port is wrong, the certificate is not trusted, or a proxy is in the way. Check the cluster from the same machine with curl.
mapper_parsing_exception A document does not fit an existing field. SPSync starts a _v2 index after a column changes type; if you changed an index by hand, delete it and run a reconcile.