Integration of Elasticsearch with 1C-Bitrix

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1175
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Elasticsearch Integration with Bitrix CMS

The built-in Bitrix search relies on b_search_content and b_search_content_stem tables — a morphological index based on MySQL/MariaDB. When 50–100 thousand documents are indexed, full-text queries start producing delays of 200–500 ms. For catalogs with a million SKUs or when complex search filters are needed (price range, multiple facets simultaneously), the built-in search becomes a bottleneck. Elasticsearch solves both problems: it returns results in 5–30 ms and supports arbitrary aggregations.

Integration Architecture

The integration consists of three parts:

  1. Indexer — a component that reads data from Bitrix (infoblock elements, users, pages) and writes documents to the Elasticsearch index.
  2. Search gateway — replaces standard b_search_content queries with Elasticsearch API calls.
  3. Event handlers — update the index when entities are modified or deleted.

Index Structure for Product Catalog

The index is created via Elasticsearch Mapping API. Example mapping for products:

PUT /bitrix_catalog
{
  "mappings": {
    "properties": {
      "id":          { "type": "integer" },
      "iblock_id":   { "type": "integer" },
      "name":        { "type": "text", "analyzer": "russian" },
      "description": { "type": "text", "analyzer": "russian" },
      "sku":         { "type": "keyword" },
      "price":       { "type": "float" },
      "active":      { "type": "boolean" },
      "section_id":  { "type": "integer" },
      "properties":  { "type": "object" },
      "updated_at":  { "type": "date" }
    }
  },
  "settings": {
    "analysis": {
      "analyzer": {
        "russian": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": ["lowercase", "russian_stop", "russian_stemmer"]
        }
      },
      "filter": {
        "russian_stemmer": { "type": "stemmer", "language": "russian" },
        "russian_stop":    { "type": "stop", "stopwords": "_russian_" }
      }
    }
  }
}

The russian analyzer with stemmer is the key difference from MySQL FULLTEXT, which cannot understand morphology without additional dictionaries.

Data Indexing

Primary indexing is launched via a cron script. Data is read in batches through CIBlockElement::GetList() with nTopCount = 100 and offset to avoid memory overload:

\Bitrix\Main\Loader::includeModule('iblock');

$client = new \Elasticsearch\ClientBuilder::create()
    ->setHosts(['localhost:9200'])
    ->build();

$offset = 0;
$batchSize = 100;

do {
    $res = \CIBlockElement::GetList(
        [],
        ['IBLOCK_ID' => CATALOG_IBLOCK_ID, 'ACTIVE' => 'Y'],
        false,
        ['nTopCount' => $batchSize, 'nPageSize' => $batchSize, 'iNumPage' => floor($offset / $batchSize) + 1],
        ['ID', 'NAME', 'DETAIL_TEXT', 'IBLOCK_ID', 'IBLOCK_SECTION_ID']
    );

    $bulk = [];
    while ($item = $res->GetNext()) {
        $bulk[] = ['index' => ['_index' => 'bitrix_catalog', '_id' => $item['ID']]];
        $bulk[] = [
            'id'         => (int)$item['ID'],
            'iblock_id'  => (int)$item['IBLOCK_ID'],
            'name'       => $item['NAME'],
            'description'=> strip_tags($item['DETAIL_TEXT']),
            'section_id' => (int)$item['IBLOCK_SECTION_ID'],
            'active'     => true,
            'updated_at' => date('c'),
        ];
        $offset++;
    }

    if (!empty($bulk)) {
        $client->bulk(['body' => $bulk]);
    }
} while ($res->SelectedRowsCount() === $batchSize);

The Bulk API allows sending up to 1000 documents per request. Do not use individual index requests for primary indexing — that's 10–50 times slower.

Index Update on Product Change

Subscribe to infoblock events:

// local/php_interface/init.php
AddEventHandler('iblock', 'OnAfterIBlockElementUpdate', 'esUpdateProduct');
AddEventHandler('iblock', 'OnAfterIBlockElementDelete', 'esDeleteProduct');

function esUpdateProduct(array &$arFields): void
{
    $client = getEsClient();
    $productId = (int)$arFields['ID'];
    // Reindex single document
    $client->index([
        'index' => 'bitrix_catalog',
        'id'    => $productId,
        'body'  => buildProductDocument($productId),
    ]);
}

function esDeleteProduct(int $productId): void
{
    getEsClient()->delete(['index' => 'bitrix_catalog', 'id' => $productId]);
}

The OnAfterIBlockElementUpdate event fires even when changing data via API (importing from 1C), which is important for index freshness.

Search Query

Replacing the standard bitrix:search.page component with a custom one that calls Elasticsearch:

$response = $client->search([
    'index' => 'bitrix_catalog',
    'body'  => [
        'query' => [
            'multi_match' => [
                'query'     => $searchQuery,
                'fields'    => ['name^3', 'description', 'sku'],
                'type'      => 'best_fields',
                'fuzziness' => 'AUTO',
            ],
        ],
        'sort'  => ['_score' => ['order' => 'desc']],
        'from'  => ($page - 1) * $pageSize,
        'size'  => $pageSize,
    ],
]);

The fuzziness: AUTO parameter enables typo-tolerant search: for words up to 5 characters, 1 substitution is allowed; for longer words, 2 are allowed.

Implementation Timeline

Scale Scope Timeline
Basic ES installation, mapping, indexer, search gateway 5–7 days
Full Faceted search via aggregations, suggestions (suggest), synonyms, autocomplete 10–14 days