TABLE OF CONTENTS
- Elasticsearch Configuration
- Elasticsearch API
- Listing All Indices
- Deleting Indices
- Kibana for Elasticsearch Data Visualization
- Resolving a duplicate Elasticsearch index
- Official Elasticsearch Documentation
Search functionality in the Znode WebStore is built on top of Elasticsearch. Each catalog in Znode is published to Elasticsearch as a single independent Elasticsearch index.
As a Znode developer, it's typically unnecessary to directly interact with Elasticsearch. However, it's helpful to understand a few simple Elasticsearch commands that can be useful during development.
In Znode the following layered structure is used to provide to implement Search in Znode.
- Admin UI Layer - Znode Admin screens that expose Znode’s search functionality as configuration
- API Layer - Znode endpoints that expose Znode’s search functionality as a web service - Znode endpoints that expose Znode’s search functionality as a web service
- Service Layer - Znode logic that uses Nest to interact with Elasticsearch
- Elasticsearch Nest Client - Elasticsearch client
- Elasticsearch - A search engine that uses Lucene and exposes JSON-based API
- Apache Lucene - Core search library that does all language processing/analysis
Elasticsearch Configuration
The Elasticsearch server to which Znode points is configured in the API's web.config. More detail about the ElasticsearchRootUri setting is here.
Elasticsearch index name configuration is stored in the SQL database. More detail about Elasticsearch index names is here.
Elasticsearch API
Elasticsearch itself provides access to all of its functionality via its built-in RESTful API that is automatically available on any installation. By default, this API is hosted on port 9200 of the machine it is installed on.
It's possible to verify that Elasticsearch is running properly, by simply sending a GET request to the root of the Elasticsearch API. Quite simply, navigating to http://localhost:9200/ in a browser will send this request and show the result. The result should be something like the following:
"name" : "System_Name", "cluster_name" : "elasticsearch", "cluster_uuid" : "sok185AYTuOgwkcEyBT17A", "version" : { "number" : "8.8.1", "build_flavor" : "default", "build_type" : "zip", "build_hash" : "f8edfccba429b6477927a7c1ce1bc6729521305e", "build_date" : "2023-06-05T21:32:25.188464208Z", "build_snapshot" : false, "lucene_version" : "9.6.0", "minimum_wire_compatibility_version" : "7.17.0", "minimum_index_compatibility_version" : "7.0.0" }, "tagline" : "You Know, for Search" }
Listing All Indices
A summary of all Elasticsearch indices can be viewed by loading the following URL in a browser: http://localhost:9200/_cat/indices?v. The result will look something like the following:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open carsuppliesindex Yz2zOC-8R8yP3DadpBGfpQ 5 1 129 0 101.4kb 101.4kb
yellow open finefoodindex fXKyiPu3R6y1sYXCRajX0Q 5 1 448 0 3.8mb 3.8mb
This example shows that there are 2 indices, corresponding to 2 different catalogs in Znode. The docs.count and other properties will grow as more products are added to the catalog and published.
See List All Indices in Elasticsearch's official documentation for more info.
Deleting Indices
Under normal circumstances, it is not necessary to rebuild indices in Elasticsearch. However, it can be helpful during development, when diagnosing functional/performance issues or migrating data between environments.
Like many Elasticsearch operations, deleting an index is as simple as sending an HTTP request to the Elasticsearch REST API. An HTTP DELETE request must be sent to the URL http://localhost:9200/{index_name} where {index_name} must be replaced with the name of the index to delete. For example, to delete the index for the CarSupplies catalog, a DELETE request must be sent to http://localhost:9200/carsuppliesindex.
See Delete Index in Elasticsearch's official documentation for more info about deleting an index.
Kibana for Elasticsearch Data Visualization
An official, open-source, Elasticsearch visualization tool can be easily installed to make it easier to audit/understand the data held in Elasticsearch. The tool is called Kibana.
Here is an example of a Kibana dashboard built to visualize timing data:
Resolving a duplicate Elasticsearch index
If there is a publishing issue, the administrator can see the application logs to determine if there is a duplicate Elasticsearch index. The duplicate index needs to be deleted and a full store publish including the store, catalog, cms should be done. The following options can be run.
- Clear Publish Data
Go into Admin > Dev Center > Diagnostic & Maintenance > Maintenance > Clear Data
Do a full store publish
Verify publish works, if it still errors, proceed to step 2.
- Manually delete the Elasticsearch index (Only do this if step 1 fails.
Go into Admin >Marketing> Site Search (Search Settings > Manage PIM Indexes
Take note of the index name
Run the following PowerShell command
Invoke-WebRequest -Uri
Invoke-WebRequest -Uri http://localhost:9200/IndexToBeDeleted -Method delete
Were the localhost is the Elasticsearch URL and the index name is the index to be deleted (in step 2a)
Run command, you should see a successful return
verifying the Index is deleted from http://localhost:9200/_cat/indices?v
Do a full store publish.
Official Elasticsearch Documentation
Official full documentation for Znode's version of Elasticsearch, v7.16.2, is available on Elastic's website here.