Introduction
OpenSearch is a distributed, RESTful search and analytics engine built on Apache Lucene. Originally forked from Elasticsearch in 2021, OpenSearch provides powerful full-text search capabilities, real-time analytics, and visualization tools. In 2026, OpenSearch continues to evolve as a leading open-source search platform.
This comprehensive guide covers everything you need to get started with OpenSearch.
What is OpenSearch?
OpenSearch is a distributed search engine that provides:
- Full-Text Search: Powerful text matching with relevance scoring
- Real-Time Analytics: Aggregate and analyze data in near real-time
- Distributed Architecture: Scale horizontally across clusters
- RESTful API: Easy HTTP-based interactions
- Visualization: Built-in dashboards with OpenSearch Dashboards
OpenSearch vs Elasticsearch
| Feature | OpenSearch | Elasticsearch |
|---|---|---|
| License | Apache 2.0 | SSPL |
| Governance | AWS/OpenSearch Community | Elastic |
| Security | Built-in | XPack (paid) |
| Visualization | OpenSearch Dashboards | Kibana (paid features) |
Installation
Docker Installation
# Start OpenSearch
docker run -d --name opensearch \
-p 9200:9200 \
-p 9600:9600 \
-e "discovery.type=single-node" \
-e "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" \
opensearchproject/opensearch:latest
# Start OpenSearch Dashboards
docker run -d --name opensearch-dashboards \
-p 5601:5601 \
-e OPENSEARCH_HOSTS=https://opensearch:9200 \
opensearchproject/opensearch-dashboards:latest
OpenSearch DSL Basics
Creating Indexes
PUT /products
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"name": { "type": "text" },
"price": { "type": "float" },
"category": { "type": "keyword" },
"in_stock": { "type": "boolean" },
"created_at": { "type": "date" }
}
}
}
Document Operations
# Index a document
POST /products/_doc
{
"name": "Wireless Mouse",
"price": 29.99,
"category": "Electronics",
"in_stock": true,
"created_at": "2026-03-05T10:00:00Z"
}
# Get a document
GET /products/_doc/1
# Update
POST /products/_update/1
{ "doc": { "price": 24.99 } }
# Delete
DELETE /products/_doc/1
Search Queries
# Match all
GET /products/_search
{ "query": { "match_all": {} } }
# Full-text search
GET /products/_search
{ "query": { "match": { "name": "wireless mouse" } } }
# Exact match
GET /products/_search
{ "query": { "term": { "category": "Electronics" } } }
# Bool query
GET /products/_search
{
"query": {
"bool": {
"must": [{ "match": { "name": "mouse" } }],
"filter": [
{ "term": { "in_stock": true } },
{ "range": { "price": { "lte": 50 } } }
]
}
}
}
Aggregations
# Terms aggregation
GET /products/_search
{
"size": 0,
"aggs": {
"categories": { "terms": { "field": "category" } }
}
}
# Average
GET /products/_search
{
"size": 0,
"aggs": {
"avg_price": { "avg": { "field": "price" } }
}
}
Data Types
Core Types
{
"properties": {
"text_field": { "type": "text" },
"keyword_field": { "type": "keyword" },
"int_field": { "type": "integer" },
"long_field": { "type": "long" },
"float_field": { "type": "float" },
"bool_field": { "type": "boolean" },
"date_field": { "type": "date" },
"geo_field": { "type": "geo_point" }
}
}
Python Integration
from opensearchpy import OpenSearch
client = OpenSearch(
hosts=[{'host': 'localhost', 'port': 9200}]
)
# Create index
client.indices.create(
index='products',
body={
'mappings': {
'properties': {
'name': {'type': 'text'},
'price': {'type': 'float'}
}
}
}
)
# Index document
client.index(index='products', body={'name': 'Mouse', 'price': 29.99})
# Search
response = client.search(
index='products',
body={'query': {'match': {'name': 'mouse'}}}
)
Conclusion
OpenSearch provides powerful search and analytics with a RESTful API. Understanding OpenSearch DSL enables building sophisticated search applications.
Comments