Elasticsearch Configuration
Introduction
Elasticsearch is a distributed search and analytics engine designed for scalability and real-time data processing. This guide provides the necessary steps to install, configure, and use Elasticsearch in the UnoPim project.
Installing Elasticsearch on Ubuntu Server
Follow the steps below to install Elasticsearch (v8.x) on Ubuntu 22.04 or 24.04:
🔎 Note: Before proceeding, check if Elasticsearch is already installed:
dpkg -l | grep elasticsearch
# or
elasticsearch --version- If a version is displayed → Elasticsearch is already installed, skip installation.
- If no output → continue with installation.
Step 1: Install Required Dependencies
sudo apt-get update
sudo apt-get install apt-transport-https curl gnupg -yStep 2: Add Elasticsearch GPG Key
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpgStep 3: Add Elasticsearch Repository
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.listStep 4: Install Elasticsearch
sudo apt-get update
sudo apt-get install elasticsearch -yStep 5: Enable and Start Elasticsearch
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
sudo systemctl status elasticsearch.serviceStep 6: Verify Installation
curl 'http://localhost:9200'You should see a JSON response with cluster information.
Step 7: Optimize Linux Kernel Settings
Elasticsearch requires a higher vm.max_map_count value. Run:
sudo sysctl -w vm.max_map_count=262144
echo "vm.max_map_count=262144" | sudo tee /etc/sysctl.d/elasticsearch.conf
sudo systemctl restart elasticsearchConfiguring UnoPim to Use Elasticsearch
Environment Variables
Add the following settings to your .env file:
ELASTICSEARCH_ENABLED=true
ELASTICSEARCH_CONNECTION=default
ELASTICSEARCH_HOST=localhost:9200
ELASTICSEARCH_USER=
ELASTICSEARCH_PASS=
ELASTICSEARCH_API_KEY=
ELASTICSEARCH_CLOUD_ID=
ELASTICSEARCH_INDEX_PREFIX=unopim_testingExplanation of Variables
- ELASTICSEARCH_ENABLED: Enables or disables Elasticsearch (
true/false) - ELASTICSEARCH_CONNECTION: Type of connection (
default,cloud, orapi) - ELASTICSEARCH_HOST: Server location (
localhost:9200orelastic.example.com:9200) - ELASTICSEARCH_USER / ELASTICSEARCH_PASS: Basic auth credentials (optional)
- ELASTICSEARCH_API_KEY: Base64-encoded API key (optional)
- ELASTICSEARCH_CLOUD_ID: Required only for Elastic Cloud deployments
- ELASTICSEARCH_INDEX_PREFIX: Prefix for indices (e.g.,
unopim_dev_,unopim_prod_)
Cache Configuration
After updating .env, run:
php artisan config:cacheIndexing Commands
- Clear Indexes
php artisan unopim:elastic:clear⚠️ Remove all indexed data and indexes for categories and products.
- Index Products
php artisan unopim:product:index- Index Categories
php artisan unopim:category:indexFilter Improvements (v2.0.0)
UnoPim v2.0.0 includes several improvements to Elasticsearch filter handling:
- SKU Filters — Improved handling for exact and partial SKU matching.
- Text Filters — Better support for text-based attribute filtering with improved tokenization.
- Option Filters — Enhanced array and
CONTAINShandling for select/multiselect attribute options.
These improvements provide more accurate search results when filtering products by attributes in the admin panel and API.