Installation
OpenSearch Installation
# Ubuntu/Debian
wget -qO - https://artifacts.opensearch.org/publickeys/opensearch.pgp | sudo apt-key add -
sudo add-apt-repository https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt
sudo apt update
sudo apt install opensearch
# Start service
sudo systemctl start opensearch
sudo systemctl enable opensearch
Elasticsearch Installation
# Ubuntu/Debian
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo add-apt-repository https://artifacts.elastic.co/packages/8.x/apt
sudo apt update
sudo apt install elasticsearch
# Start service
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
Default Configuration
# /etc/opensearch/opensearch.yml
cluster.name: magento-search
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
discovery.type: single-node
Verify Installation
# Test connection
curl -X GET "http://localhost:9200"
# Check cluster health
curl -X GET "http://localhost:9200/_cluster/health"
Magento Configuration
env.php Configuration
return [
'catalog' => [
'search' => [
'engine' => 'elasticsearch8',
'engine_config' => [
'host' => 'localhost',
'port' => '9200',
'index' => 'magento2'
]
]
]
];
CLI Setup
php bin/magento setup:config:set \
--search-engine=elasticsearch8 \
--elasticsearch-host=localhost \
--elasticsearch-port=9200 \
--elasticsearch-index-prefix=magento2
Connection Test
# Test connection from Magento
php bin/magento search-engine:test
# Check search engine status
php bin/magento search-engine:status
Multiple Search Engines
// env.php for different environments
'catalog' => [
'search' => [
'engine' => 'elasticsearch8',
'engine_config' => [
'host' => env('ES_HOST', 'localhost'),
'port' => env('ES_PORT', '9200'),
'index' => env('ES_INDEX', 'magento2')
]
]
]
Index Management
Create Search Index
# Create index
php bin/magento search-engine:create
# Delete index
php bin/magento search-engine:delete
# Reindex
php bin/magento indexer:reindex catalogsearch_fulltext
Index Structure
{
"magento2_product_1": {
"mappings": {
"properties": {
"sku": { "type": "text" },
"name": { "type": "text" },
"description": { "type": "text" },
"category_ids": { "type": "integer" },
"price": { "type": "float" }
}
}
}
}
Index Aliases
# Check aliases
curl -X GET "http://localhost:9200/_aliases"
# Create alias
curl -X POST "http://localhost:9200/_aliases" -H 'Content-Type: application/json' -d '{
"actions": [{ "add": { "index": "magento2_product_1", "alias": "magento2_product" }}]
}'
Index Monitoring
# Check index stats
curl -X GET "http://localhost:9200/_stats"
# Check index size
curl -X GET "http://localhost:9200/_cat/indices?v"
# Check index health
curl -X GET "http://localhost:9200/_cat/health?v"
Performance Tuning
JVM Settings
# /etc/opensearch/jvm.options
-Xms2g # Min heap (set to 50% of RAM, max 32g)
-Xmx2g # Max heap
System Settings
# Increase file descriptors
sudo sysctl -w vm.max_map_count=262144
# Persist setting
echo "vm.max_map_count=262144" | sudo tee -a /etc/sysctl.conf
Index Settings
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1,
"refresh_interval": "1s"
}
}
Query Performance
// Magento search settings
'search' => [
'max_execution_time' => 3,
'minimum_should_match' => '75%',
'fuzziness' => 'AUTO'
]
Monitoring
# Cluster health
curl -X GET "http://localhost:9200/_cluster/health?pretty"
# Node stats
curl -X GET "http://localhost:9200/_nodes/stats?pretty"
# Index stats
curl -X GET "http://localhost:9200/_stats?pretty"
Practice Problems
Configure OpenSearch for a Magento store with 100k products and optimize for search performance.
Quiz
1. What is the default port for OpenSearch/Elasticsearch?
2. What JVM setting controls heap size?
3. What command tests search engine connection?
4. What is the recommended JVM heap size for search?
Flashcards
Question
What port does OpenSearch use?
Click to reveal answer
Answer
9200 for HTTP connections
Question
How to set JVM heap size?
Click to reveal answer
Answer
-Xms (min) and -Xmx (max) in jvm.options
Question
How to test search connection?
Click to reveal answer
Answer
php bin/magento search-engine:test
Question
What is the recommended heap size?
Click to reveal answer
Answer
50% of RAM, max 32GB
Question
How to create search index?
Click to reveal answer
Answer
php bin/magento search-engine:create
Revision Notes
Key Takeaways
- 1. OpenSearch/Elasticsearch runs on port 9200
- 2. Configure JVM heap as 50% of RAM (max 32GB)
- 3. Set vm.max_map_count=262144 for production
- 4. Use search-engine:test to verify connection
- 5. Create and manage indexes with search-engine:create/delete
- 6. Monitor cluster health with _cluster/health endpoint
Interview Tips
- • Explain OpenSearch installation and configuration
- • Discuss JVM tuning for search performance
- • Describe index management commands
- • Know how to monitor search engine health
Cheat Sheet
OpenSearch Cheat Sheet
Port: 9200
Config:
'catalog' => ['search' => [
'engine' => 'elasticsearch8',
'engine_config' => ['host' => 'localhost', 'port' => '9200']
]]
JVM:
-Xms2g -Xmx2g (50% RAM, max 32GB)
System:
vm.max_map_count=262144
Commands:
search-engine:test
search-engine:status
search-engine:create
Monitor:
curl localhost:9200/_cluster/health