What is OpenSearch?
OpenSearch is a scalable, open-source search and analytics suite forked from Elasticsearch. It's maintained by AWS and offers full compatibility with Elasticsearch APIs.
bash
# Install OpenSearch
docker run -p 9200:9200 -p 9600:9600 \
-e "discovery.type=single-node" \
opensearchproject/opensearch:latestKey Features
Distributed Architecture
json
// Cluster configuration
{
"cluster": {
"name": "my-opensearch-cluster"
},
"node": {
"name": "node-1"
}
}Index Management
bash
# Create index
curl -X PUT "localhost:9200/products" \
-H 'Content-Type: application/json' \
-d '{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 2
},
"mappings": {
"properties": {
"name": { "type": "text" },
"price": { "type": "float" },
"category": { "type": "keyword" }
}
}
}'OpenSearch Dashboards
Data Visualization
json
// Create index pattern
{
"attributes": {
"title": "products*",
"timeFieldName": "created_at"
}
}Dashboards
json
// Create visualization
{
"type": "line",
"title": "Sales Over Time",
"params": {
"index_pattern": "products",
"time_field": "created_at",
"metrics": [{ "type": "sum", "field": "price" }]
}
}Security
Authentication
bash
# Enable security plugin
opensearch-security-admin.sh \
-cd /usr/share/opensearch/plugins/opensearch-security/securityconfig \
-icl \
-nhnv \
-cacert /usr/share/opensearch/config/root-ca.pem \
-cert /usr/share/opensearch/config/admin.pem \
-key /usr/share/opensearch/config/admin-key.pemSQL Support
OpenSearch SQL
sql
-- Query using SQL
SELECT category, AVG(price) as avg_price
FROM products
WHERE created_at >= '2025-01-01'
GROUP BY category
ORDER BY avg_price DESCbash
# Execute SQL
curl -X POST "localhost:9200/_plugins/_sql" \
-H 'Content-Type: application/json' \
-d '{
"query": "SELECT * FROM products WHERE price > 100"
}'Migration from Elasticsearch
Compatibility
bash
# OpenSearch is largely compatible with Elasticsearch 7.x
# Most queries work without modification
# Reindex from Elasticsearch
curl -X POST "localhost:9200/_reindex" \
-H 'Content-Type: application/json' \
-d '{
"source": {
"remote": {
"host": "https://old-elasticsearch:9200"
},
"index": "products"
},
"dest": {
"index": "products"
}
}'Best Practices
- 1Use appropriate shard count
- 2Enable security for production
- 3Monitor cluster health
- 4Use OpenSearch Dashboards for visualization
- 5Leverage SQL for complex queries
Conclusion
OpenSearch provides a powerful, open-source alternative to Elasticsearch with enhanced features and AWS integration.
Migrate to OpenSearch for better search!