OpenSearch
What is OpenSearch?
OpenSearch is a distributed, community-driven, Apache 2.0-licensed, 100% open-source search and analytics suite used for a wide range of use cases such as real-time application monitoring, log analytics, and website search. OpenSearch provides a highly scalable system for fast access and response to large volumes of data, with an integrated visualization tool, OpenSearch Dashboards, which makes it easy for users to explore their data. OpenSearch is built on the Apache Lucene search library and supports a variety of search and analytics features.
OpenSearch originated as an open-source fork of ElasticSearch after the latter stopped offering a fully open-source version. Using OpenSearch has the advantage that, among other things, full-text search and many other features are available that can extend the search and analytics capabilities of a CMS. For Magento >=2.4, OpenSearch is a prerequisite for installation.
As a fork of Elasticsearch, OpenSearch is fully compatible with Elasticsearch APIs and plugins.
Creating an OpenSearch database
You can provision an OpenSearch database in your mittwald hosting environment using containers. There are two main approaches:
Using Terraform (Recommended)
The most convenient way to provision an OpenSearch database is using Terraform with our OpenSearch module. The following example shows how you can use this module in your own Terraform deployment:
resource "random_password" "opensearch_admin" {
length = 16
special = true
}
module "opensearch" {
source = "mittwald/opensearch/mittwald"
project_id = "<project-id>"
initial_admin_password = random_password.opensearch_admin.result
}
output "opensearch_url" {
value = module.opensearch.url
}
After this, you can access your OpenSearch backend using the URL returned by the module. Usually, the URL should be https://opensearch:9200
. The default username is admin
, and the password is the one generated by the random_password
resource.
Using the mStudio UI
Alternatively, you can set up an OpenSearch container manually:
-
Go to Containers in your project in mStudio and create a new one. You can choose any name you like.
-
Enter the image
opensearchproject/opensearch
. You can keep the entrypoint and command as suggested. -
To make your OpenSearch data persistent, create a volume under Volumes as follows:
- Volume: Create new volume
- Path in container (Mount Point):
/usr/share/opensearch/data
-
Set the following environment variables for the container:
OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m # limits OpenSearch RAM usage - extremely important, otherwise 32 GB RAM will be consumed
bootstrap.memory_lock=true # together with the previous line ensures no swapping occurs
cluster.name=opensearch-cluster # name for the OS cluster
discovery.seed_hosts=opensearch-test # specifies which node should be used in the cluster
node.name=opensearch-test # name for the OS node
plugins.security.ssl.http.enabled=false # enables connection via HTTP, since containers cannot handle HTTPS
discovery.site=single-node
OPENSEARCH_INITIAL_ADMIN_PASSWORD=SuperSecurePassword123 # sets the admin password. Since version 2.12 this is mandatory
The default user for OpenSearch is admin
.
The suggested port values are standard in the OpenSearch context and can be accepted as is.
Using the CLI with mw container run
You can also deploy an OpenSearch container using the mittwald CLI with the mw container run
command:
mw container run \
--name opensearch \
--env OPENSEARCH_JAVA_OPTS=-Xms512m\ -Xmx512m \
--env bootstrap.memory_lock=true \
--env cluster.name=opensearch-cluster \
--env discovery.seed_hosts=opensearch \
--env node.name=opensearch \
--env plugins.security.ssl.http.enabled=false \
--env discovery.type=single-node \
--env OPENSEARCH_INITIAL_ADMIN_PASSWORD=SuperSecurePassword123 \
--volume opensearch-data:/usr/share/opensearch/data \
--create-volumes \
opensearchproject/opensearch
This command creates a new container named "opensearch" using the OpenSearch image, sets all the necessary environment variables, and mounts a volume for persistent data storage.
Using the CLI with mw stack deploy
If you prefer using Docker Compose, you can create a docker-compose.yml
file and deploy it using the mw stack deploy
command:
-
Create a
docker-compose.yml
file with the following content:version: "3"
services:
opensearch:
image: opensearchproject/opensearch
environment:
- OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m
- bootstrap.memory_lock=true
- cluster.name=opensearch-cluster
- discovery.seed_hosts=opensearch
- node.name=opensearch
- plugins.security.ssl.http.enabled=false
- discovery.type=single-node
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=SuperSecurePassword123
volumes:
- opensearch-data:/usr/share/opensearch/data
volumes:
opensearch-data: -
Deploy the stack using the CLI:
mw stack deploy
This approach is particularly useful when you need to deploy multiple containers that work together, such as OpenSearch with OpenSearch Dashboards.
Accessing your container within your hosting environment
Once the container is running, you can verify the instance is accessible by requesting it via curl
:
curl -X GET "https://opensearch:9200" -ku admin:SuperSecurePassword123
You should receive a response similar to:
{
"name": "c-fdbzvx-0",
"cluster_name": "docker-cluster",
"cluster_uuid": "hABJsptAR9uw7cBXtqaneA",
"version": {
"distribution": "opensearch",
"number": "2.19.1",
"build_type": "tar",
"build_hash": "2e4741fb45d1b150aaeeadf66d41445b23ff5982",
"build_date": "2025-02-27T01:16:47.726162386Z",
"build_snapshot": false,
"lucene_version": "9.12.1",
"minimum_wire_compatibility_version": "7.10.0",
"minimum_index_compatibility_version": "7.0.0"
},
"tagline": "The OpenSearch Project: https://opensearch.org/"
}
Operation
OpenSearch runs as long as the container is running. When using OpenSearch as a search engine for your CMS, the search indices need to be populated by your application. For this, most CMS platforms offer integrations.
The volume is automatically included in the regular backup of your project.
Setting up common applications
To integrate OpenSearch into applications, an entry is usually required in the configuration file of the CMS. In this section, you will find examples for various CMS platforms.
Magento 2
For Magento 2, the hostname is simply entered in the app's installation menu. The setup automatically handles the configuration.
Shopware 6
In Shopware, the .env
or .env.local
files already contain lines where connection data must be stored:
SHOPWARE_ES_ENABLED=1
SHOPWARE_ES_HOSTS="http://USERNAME:PASSWORD@hostname:9200"
SHOPWARE_ES_INDEXING_ENABLED=1
SHOPWARE_ES_INDEX_PREFIX=sw
SHOPWARE_ES_THROW_EXCEPTION=0
USERNAME is always admin
in our case. The PASSWORD is the OPENSEARCH_INITIAL_ADMIN_PASSWORD
we set.
Afterwards, the index must be populated via the Shopware console using this command:
php bin/console es:admin:index
To make it visible in the frontend, the consumer must be running and the cache cleared.
TYPO3
TYPO3 does not natively support OpenSearch, so an extension is required. One possible integration would be pluswerk/elasticsearch
.
WordPress
WordPress cannot natively connect to OpenSearch, but you can use the ElasticPress plugin for this. The connection settings must be adjusted in the plugin backend because the CLI extension of ElasticPress cannot handle the initial setup. Afterwards, indexing can be enabled using the command:
wp elasticpress index --setup