Skip to main content

OpenSearch

Versions

VersionStatus
2Available

Connecting

ParameterValue
Host{name}.db.foundrydb.com
Port9200
AuthHTTP Basic
TLSRequired
# Health check
curl -u USER:PASS https://HOST:9200/_cluster/health

# Create an index
curl -u USER:PASS -X PUT https://HOST:9200/my-index \
-H "Content-Type: application/json" \
-d '{"settings": {"number_of_shards": 3, "number_of_replicas": 1}}'

Python (opensearch-py)

from opensearchpy import OpenSearch
client = OpenSearch(
hosts=[{'host': 'HOST', 'port': 9200}],
http_auth=('USER', 'PASS'),
use_ssl=True,
verify_certs=True,
)
resp = client.cluster.health()

Node.js (@opensearch-project/opensearch)

import { Client } from '@opensearch-project/opensearch';
const client = new Client({
node: 'https://HOST:9200',
auth: { username: 'USER', password: 'PASS' },
});

Indexes

Create

curl -u USER:PASS -X PUT https://HOST:9200/products \
-H "Content-Type: application/json" \
-d '{
"settings": {"number_of_shards": 3, "number_of_replicas": 1},
"mappings": {
"properties": {
"name": {"type": "text"},
"price": {"type": "float"},
"tags": {"type": "keyword"}
}
}
}'

Index a document

curl -u USER:PASS -X POST https://HOST:9200/products/_doc \
-H "Content-Type: application/json" \
-d '{"name": "Widget", "price": 9.99, "tags": ["hardware", "tools"]}'
curl -u USER:PASS -X GET https://HOST:9200/products/_search \
-H "Content-Type: application/json" \
-d '{"query": {"match": {"name": "widget"}}}'

Index Lifecycle Management

Automatically manage index rollover and deletion:

curl -u USER:PASS -X PUT https://HOST:9200/_plugins/_ism/policies/log-policy \
-H "Content-Type: application/json" \
-d '{
"policy": {
"description": "Delete logs after 30 days",
"states": [{
"name": "hot",
"actions": [],
"transitions": [{"state_name": "delete", "conditions": {"min_index_age": "30d"}}]
}, {
"name": "delete",
"actions": [{"delete": {}}],
"transitions": []
}]
}
}'

Scaling

Add data nodes for more storage and throughput:

curl -u admin:password -X POST \
https://api.foundrydb.com/managed-services/{id}/nodes \
-H "Content-Type: application/json" \
-d '{"role": "data"}'

Snapshots

# Manual snapshot
curl -u admin:password -X POST \
https://api.foundrydb.com/managed-services/{id}/backups \
-H "Content-Type: application/json" \
-d '{"backup_type": "manual"}'

# List snapshots
curl -u admin:password \
https://api.foundrydb.com/managed-services/{id}/backups

Configuration

curl -u admin:password -X PATCH \
https://api.foundrydb.com/managed-services/{id}/configuration \
-H "Content-Type: application/json" \
-d '{
"parameters": {
"indices.fielddata.cache.size": "20%",
"indices.breaker.total.limit": "70%",
"thread_pool.search.queue_size": "1000"
}
}'

Metrics

Key metrics: cluster_health, active_shards, indexing_rate, search_rate, jvm_heap_used, fielddata_evictions.

curl -u admin:password \
"https://api.foundrydb.com/managed-services/{id}/metrics?metric=indexing_rate&period=1h"