# Using Elasticsearch with Magento

> Configure Magento 2.4 and later to use Elasticsearch for faster, more accurate product search, then test that it works.

Source: https://helpcenter.ruachost.com/apps/magento/using-elasticsearch-with-magento/

**Elasticsearch** is a powerful search engine that improves product search speed and accuracy in Magento. It replaces the default MySQL search with a scalable, full‑text search solution. On **ruachost.com**, Elasticsearch is supported for Magento 2.4 and later.

## Why Use Elasticsearch?

- Provides **fast, relevant search results** for customers.
- Supports advanced features like **autocomplete, synonyms, and spell correction**.
- Scales easily for large catalogs with thousands of products.
- Improves overall site performance compared to MySQL search.

## Steps to Configure Magento with Elasticsearch

### Step 1: Ensure Elasticsearch is Installed

- On **Managed VPS/Dedicated Servers** → Ruachost support can install Elasticsearch for you.
- On **Unmanaged VPS** → Install manually via SSH:

  ```bash
  apt-get install elasticsearch
  ```

  or

  ```bash
  yum install elasticsearch
  ```

### Step 2: Configure Magento to Use Elasticsearch

1. Log in to Magento Admin.
2. Go to **Stores → Configuration → Catalog → Catalog Search**.
3. Under **Search Engine**, select **Elasticsearch**.
4. Configure the following settings:

   - **Elasticsearch Server Hostname** → `127.0.0.1` (or your server’s IP).
   - **Elasticsearch Server Port** → `9200`.
   - **Index Prefix** → Optional, useful for multiple Magento installations.
   - **Enable Elasticsearch HTTP Auth** → Yes/No depending on your setup.
   - **Elasticsearch Server Timeout** → Recommended: `15`.
5. Save configuration.

### Step 3: Test Elasticsearch Integration

- Run reindexing via CLI:

  ```bash
  php bin/magento indexer:reindex
  ```
- Clear cache:

  ```bash
  php bin/magento cache:flush
  ```
- Test product search in your storefront.

## Important Notes

- Elasticsearch is **required** for Magento 2.4 and newer.
- Ensure your server meets memory requirements (at least **2GB RAM** for Elasticsearch).
- If using multiple stores, configure separate index prefixes.
- Always back up your site before making configuration changes.
