Book Contents

Book Index

Elasticsearch K2

Book Contents

Book Index

Introduction and description of the architecture

The Elasticsearch tool is used for fast and efficient searching within the e-shop and IS K2. It offers full-text search including inflection, the use of synonyms, typo detection and sorting of results by relevance.

It also allows searching in the names and descriptions of article categories, product brands, or the titles and content of blog articles. Evaluation can be performed through integration with the Google Analytics service.

Elasticsearch itself is a multiplatform open-source product that must be installed separately. Both IS K2 and the K2 e-shop implement a communication interface through which they can communicate with Elasticsearch.

For overall functionality, it is necessary to ensure that communication with this server is possible on TCP port 9200 (default setting) both from the internal network from the K2 Application server service, or from the terminal server/client stations on which users run IS K2, and from the K2 e-shop side (i.e. typically a server located in the DMZ).

Book Contents

Book Index

Recommended production deployment (Linux)

Deployment on a separate server on the Linux platform located in the DMZ.

Minimum requirements: 8GB RAM, 2 CPU cores, 30GB disk.

pic_5896

Picture: Recommended production deployment (Linux)

Book Contents

Book Index

Deployment for testing (Windows)

A variant for test operation of the e-shop. Unsupported for production operation.

Besides the requirements of other services, the AS server must additionally have at least 2GB RAM and available CPU capacity for running Elasticsearch.

pic_5897

Picture: Deployment for testing (Windows)

Book Contents

Book Index

Elasticsearch installation (Linux)

Various options of the basic installation on the Linux platform are described in detail on the Elasticsearch vendor's website:

https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html

In addition to the basic installation, the following add-ons need to be installed:

- ICU Analysis plugin: https://www.elastic.co/guide/en/elasticsearch/plugins/current/analysis-icu.html

- Dictionaries for the languages used – see the procedure in the chapter "Installing dictionaries for Elasticsearch".

Book Contents

Book Index

Elasticsearch installation (Windows)

Various options of the basic installation on the Linux platform are described in detail on the Elasticsearch vendor's website:

https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html

In addition to the basic installation, the following add-ons need to be installed:

- ICU Analysis plugin: https://www.elastic.co/guide/en/elasticsearch/plugins/current/analysis-icu.html

- Dictionaries for the languages used – see the procedure in the chapter "Installing dictionaries for Elasticsearch".

Book Contents

Book Index

Installing dictionaries for Elasticsearch

For text and word analysis to work correctly for different languages, the corresponding dictionaries of the Hunspell project need to be added to Elasticsearch.

Dictionaries for individual languages can be downloaded, for example, from this page: https://github.com/LibreOffice/dictionaries

For Czech, e.g., we download the file cs_CZ.zip. For English, en_GB.zip or en_US.zip (depending on preference for British or American English).

Extract the downloaded ZIP file into the directory with the Elasticsearch configuration files, i.e. the directory specified in the first step of the installation (here according to the default setting of the Msi installer). By default, it is C:\ProgramData\Elastic\Elasticsearch\config. Alternatively /etc/elasticsearch on the Linux platform, or the config subdirectory in the location where the Elasticsearch archive was extracted. In this directory, create a hunspell subdirectory and in it a subdirectory according to the language code (e.g. "cs_CZ"). Extract the content of the downloaded archive into the created directory (at least the files with the .aff and .dic extensions).

Next, create a settings.yml file that will contain this line:

strict_affix_parsing: true

Proceed in this way for all languages in which we need to search in the e-shop.

pic_5524.png

Picture: Example of the resulting file structure

After adding all dictionaries, the Elasticsearch service must be restarted.

Book Contents

Book Index

Installing other tools

Other tools can be installed for administration, tuning of search queries and evaluation.

Kibana: https://www.elastic.co/downloads/kibana (a tool for testing search queries and evaluation).

Cerebero: https://github.com/lmenezes/cerebro (a tool for administrators, monitoring of cluster status, etc.).

Book Contents

Book Index

Configuration in K2

First, the basic settings of the connection to the Elasticsearch service must be made. In IS K2, use the right mouse button to add the Elasticsearch configuration and Elasticsearch indexes functions from the Other section to Favourites.

Using the right mouse button or the INS key, add Elasticsearch Nodes to the Elasticsearch configuration form. Here, enter the server address including the port and the login credentials, and select the check box indicating whether we want to use Elasticsearch for the E-shop or for K2.

pic_5525_2024

Picture: Elasticsearch configuration

Using the Test the connection button, we can verify whether K2 can communicate with the Elasticsearch server. In the correct state, basic status information is displayed. In case of an error, details about the error are displayed.

The Import of default templates button imports the default templates for Elasticsearch. These templates can be displayed on the templates tab and can also be edited there. Indexes templates are described here.

pic_10011

Picture: Import of default templates

Book Contents

Book Index

Elasticsearch function for IS K2

In the Elasticsearch indexes function, we define data for Elasticsearch searching using the INS key, or with the right mouse button Record - New item.

pic_10012

Picture: New record of Elasticsearch indexes

Description of fields:

Create indexes on the ES server

Creates the defined indexes on the Elasticsearch server.

Delete indexes

Removes all selected indexes, or the index on which the cursor bar is positioned, from the Elasticsearch server, including removal of the index definition from IS K2.

Full data import

For the selected records, or the record on which the cursor bar is positioned, the data on the Elasticsearch server is deleted and created again.

Configuration of global search

The default configuration for global search is set here. This is the general configuration of global search.

Global search test

Here you can test whether global search will work in Web K2.

Export configuration

Using this function, the Elasticsearch index settings can be exported.

Import configuration

Imports the Elasticsearch index configuration from the selected file.

Elasticsearch configuration

It is described in more detail here.

Check DM integrity

This button is used after reinstalling IS K2 to check whether the structure of the data module has changed.

Book Contents

Book Index

Elasticsearch indexes

In the Indexes field, insert all data modules for which we want to set up searching.

pic_10014

Picture: Definition of the selected index

For a new index, the Identifier is set to distinguish the index on the Elasticsearch server.

pic_10013_2024_05

Picture: New index

Description of fields:

Data module

Identification of the data module.

Identifier

It is used to distinguish an entire group of indexes.

Index name

The index name is created automatically and consists of a prefix.

Last import

Date and time when the last import of the index to the Elasticsearch server was performed.

Filter

When Use filter is checked, a field for selecting the required filter of the given data module is displayed. The data will be filtered via Elasticsearch only from the specified filter.

ES status

Information on whether the index exists on the Elasticsearch server.

The following index states may be displayed:

 

pic_1266i.png

the index does not exist on the server

 

pic_1267i

the index exists on the server

 

pic_1268i

the index cannot be verified (there may be an error on the server)

The next tab is Field assignment. Here we select the fields in which the Elasticsearch search will be performed. We can define the fields ourselves or use the presets via the Insert field button. After pressing this button, a selection of fields that can be defined in the index is displayed. After selecting a field, predefined field types are displayed (e.g. Code, Name, Description, Number,...), to which analyzers are then automatically added, both for the field assignment itself and for the Autocomplete.

For the Own field type, an analyzer can be defined according to the user's choice. An own analyzer can also be defined for fields inserted using the Insert key.

On the Searching tab, we define queries for Elasticsearch searching. Autocomplete is set for the default search. The tab lists the fields in which searching will take place, the limit on the number of records, etc. For individual fields, you can also set the fuzziness tolerance, enter the field prefix length, or its priority. After switching on the Expert mode, the queries can be edited. The expert mode is not recommended unless the user really knows their way around Elasticsearch.

On the Global search tab, there is the Allowed for GS check box. This check box determines whether global search should take place in Web K2. If it is unchecked, the Elasticsearch search will take place only over indexes that have it checked.

On the Index administration tab, the following functions can be used:

You can find the default configuration of Elasticsearch indexes in the folder K2\SupportFiles\Elasticsearch\Configurations.

After setting up the Elasticsearch indexes and loading them onto the Elasticsearch server, the Elasticsearch condition can be used in the filter in IS K2, and the given search can also be used in Web K2.

For data synchronization, the following can be used in the Task scheduler:

Book Contents

Book Index

SQL server settings for using Elasticsearch

To connect the SQL server and Elasticsearch, the function 798 - SQL server settings for using elasticsearch must be used.

pic_10377

Picture: SQL server settings for using elasticsearch

In the Location of the K2SQL.dll file on the SQL server section, select the path to the file. This file must be located in a folder that is visible to the SQL server.

For the configuration with the SQL server, use the Server button and then the Client button to target a specific client.

Book Contents

Book Index

Smart Search function (e-shop)

The Smart Search function is used for fast and efficient searching within the e-shop.

You can find a more detailed description of the Smart Search (eshop) function here.

Book Contents

Book Index

Indexes templates

In the Elasticsearch configuration dialog, we also need to create Indexes templates. Each template defines the text analyzers used, including the related tokenizers and filters.

A description of these elements is beyond the scope of the K2 documentation; detailed information can be found in the Elasticsearch API documentation.

To use Elasticsearch in the K2 e-shop, an index template must be defined for each language of the website used. The templates must be named identically and differ only in the final part containing the language code.

For example:

web_search_cs

web_search_en

web_search_sk

pic_5526_2024

Picture: Elasticsearch configuration - indexes templates

Book Contents

Book Index

Example of a sample index template for Czech
{
   "settings" : {
      "index" : {
        "number_of_shards" : "1",
        "analysis" : {
          "filter" : {
            "word_delimiter_filter" : {
              "preserve_original" : "true",
              "catenate_words" : "true",
              "generate_number_parts" : "true",
              "split_on_case_change" : "false",
              "type" : "word_delimiter",
              "type_table" : [
                "/ => DIGIT",
                ". => DIGIT",
                ", => DIGIT",
                "- => ALPHANUM"
              ],
              "catenate_numbers" : "true",
              "stem_english_possessive" : "false"
            },
            "czech_hunspell" : {
              "locale" : "cs_CZ",
              "type" : "hunspell",
              "dedup" : "true"
            },
            "lowercase" : {
              "type" : "lowercase"
            },
            "min_length" : {
              "type" : "length",
              "min" : "2"
            },
            "czech_stopwords" : {
              "ignore_case" : "true",
              "type" : "stop",
              "stopwords" : [
                "že",
                "právě",
                "_czech_"
              ]
            },
            "unique" : {
              "type" : "unique",
              "only_on_same_position" : "false"
            }
          },
          "analyzer" : {
            "words" : {
              "filter" : [
                "word_delimiter_filter",
                "lowercase",
                "icu_folding",
                "unique"
              ],
              "tokenizer" : "keyword"
            },
            "autocomplete" : {
              "filter" : [
                "lowercase",                
                "icu_folding"
              ],
              "char_filter" : [
                "html_strip"
              ],
              "type" : "custom",
              "tokenizer" : "autocomplete"
            },
            "autocomplete_search" : {              
              "filter" : [              
                "icu_folding"
              ],
              "tokenizer" : "lowercase"
            },
            "hunspell" : {
              "filter" : [
                "min_length",
                "lowercase",
                "czech_hunspell",
                "czech_stopwords",
                "icu_folding",
                "unique"
              ],
              "char_filter" : [
                "html_strip"
              ],
              "type" : "custom",
              "tokenizer" : "standard"
            }
          },
          "tokenizer" : {
            "autocomplete" : {
              "token_chars" : [
                "letter",
                "digit"
              ],
              "min_gram" : "2",
              "type" : "edge_ngram",
              "max_gram" : "10"
            }
          }
        },
        "number_of_replicas" : "1"
      }
   }
}

Book Contents

Book Index

Example of a sample template for Slovak
{
   "settings" : {
      "index" : {
        "number_of_shards" : "1",
        "analysis" : {
          "filter" : {
            "word_delimiter_filter" : {
              "preserve_original" : "true",
              "catenate_words" : "true",
              "generate_number_parts" : "true",
              "split_on_case_change" : "false",
              "type" : "word_delimiter",
              "type_table" : [
                "/ => DIGIT",
                ". => DIGIT",
                ", => DIGIT",
                "- => ALPHANUM"
              ],
              "catenate_numbers" : "true",
              "stem_english_possessive" : "false"
            },
            "slovak_hunspell" : {
              "locale" : "sk_SK",
              "type" : "hunspell",
              "dedup" : "true"
            },
            "lowercase" : {
              "type" : "lowercase"
            },
            "min_length" : {
              "type" : "length",
              "min" : "2"
            },
            "slovak_stopwords" : {
              "ignore_case" : "true",
              "type" : "stop",
              "stopwords" : [
                "_slovak_"
              ]
            },
            "unique" : {
              "type" : "unique",
              "only_on_same_position" : "false"
            }
          },
          "analyzer" : {
            "words" : {
              "filter" : [
                "word_delimiter_filter",
                "lowercase",
                "icu_folding",
                "unique"
              ],
              "tokenizer" : "keyword"
            },
            "autocomplete" : {
              "filter" : [
                "lowercase",                
                "icu_folding"
              ],
              "char_filter" : [
                "html_strip"
              ],
              "type" : "custom",
              "tokenizer" : "autocomplete"
            },
            "autocomplete_search" : {              
              "filter" : [              
                "icu_folding"
              ],
              "tokenizer" : "lowercase"
            },
            "hunspell" : {
              "filter" : [
                "min_length",
                "lowercase",
                "slovak_hunspell",
                "slovak_stopwords",
                "icu_folding",
                "unique"
              ],
              "char_filter" : [
                "html_strip"
              ],
              "type" : "custom",
              "tokenizer" : "standard"
            }
          },
          "tokenizer" : {
            "autocomplete" : {
              "token_chars" : [
                "letter",
                "digit"
              ],
              "min_gram" : "2",
              "type" : "edge_ngram",
              "max_gram" : "10"
            }
          }
        },
        "number_of_replicas" : "1"
      }
   }
}

l

Book Contents

Book Index

Example of a sample index template for English (en_GB)
{
   "settings" : {
      "index" : {
        "number_of_shards" : "1",
        "analysis" : {
          "filter" : {
            "word_delimiter_filter" : {
              "preserve_original" : "true",
              "catenate_words" : "true",
              "generate_number_parts" : "true",
              "split_on_case_change" : "false",
              "type" : "word_delimiter",
              "type_table" : [
                "/ => DIGIT",
                ". => DIGIT",
                ", => DIGIT",
                "- => ALPHANUM"
              ],
              "catenate_numbers" : "true",
              "stem_english_possessive" : "false"
            },
            "slovak_hunspell" : {
              "locale" : "sk_SK",
              "type" : "hunspell",
              "dedup" : "true"
            },
            "lowercase" : {
              "type" : "lowercase"
            },
            "min_length" : {
              "type" : "length",
              "min" : "2"
            },
            "slovak_stopwords" : {
              "ignore_case" : "true",
              "type" : "stop",
              "stopwords" : [
                "_slovak_"
              ]
            },
            "unique" : {
              "type" : "unique",
              "only_on_same_position" : "false"
            }
          },
          "analyzer" : {
            "words" : {
              "filter" : [
                "word_delimiter_filter",
                "lowercase",
                "icu_folding",
                "unique"
              ],
              "tokenizer" : "keyword"
            },
            "autocomplete" : {
              "filter" : [
                "lowercase",                
                "icu_folding"
              ],
              "char_filter" : [
                "html_strip"
              ],
              "type" : "custom",
              "tokenizer" : "autocomplete"
            },
            "autocomplete_search" : {              
              "filter" : [              
                "icu_folding"
              ],
              "tokenizer" : "lowercase"
            },
            "hunspell" : {
              "filter" : [
                "min_length",
                "lowercase",
                "slovak_hunspell",
                "slovak_stopwords",
                "icu_folding",
                "unique"
              ],
              "char_filter" : [
                "html_strip"
              ],
              "type" : "custom",
              "tokenizer" : "standard"
            }
          },
          "tokenizer" : {
            "autocomplete" : {
              "token_chars" : [
                "letter",
                "digit"
              ],
              "min_gram" : "2",
              "type" : "edge_ngram",
              "max_gram" : "10"
            }
          }
        },
        "number_of_replicas" : "1"
      }
   }
}