Configuring Elasticsearch in Ucommerce
In 9.4.2, configuring Elasticsearch connections are easier than ever before.
Out of the box, you have two options:
- Single node connection for a typical developer setup
- Cloud connection typical for production
Developer setup
When you enable the Ucommerce.Search.Elasticsearch app, it connects to Elasticsearch on localhost:9200 – the default of a fresh Elasticsearch installation.
Your Configuration/Search.Elasticsearch.config
will contain this component:
<component id="ConnectionSettingsProvider" service="Ucommerce.Search.ElasticSearch.IConnectionSettingsProvider, Ucommerce.Search.ElasticSearch" type="Ucommerce.Search.ElasticSearch.SingleNodeConnectionSettingsProvider, Ucommerce.Search.ElasticSearch"> <parameters> <uri>http://localhost:9200</uri> <debug>False</debug> </parameters> </component>
No further action is needed to connect to Elasticsearch on localhost:9200
Cloud/cluster production setup
To connect to a multi node or cloud Elasticsearch environment, insert this snippet in your application specific .config file.
If you are using elastic.co to host your Elasticsearch cluster, you'll find the values of the cloudId
on the front page of your cluster deployment.
<component id="ConnectionSettingsProvider" service="Ucommerce.Search.ElasticSearch.IConnectionSettingsProvider, Ucommerce.Search.ElasticSearch" type="Ucommerce.Search.ElasticSearch.CloudConnectionSettingsProvider, Ucommerce.Search.ElasticSearch"> <parameters> <cloudId>.....</cloudId> <userName>elastic</userName> <password>.....</password> <debug>False</debug> </parameters> </component>
Advanced scenarios
You may want to connect using custom Nest.ConnectionSettings
derived type in cases where neither a SingleNodeConnectionSettingsProvider
nor a CloudConnectionSettingsProvider
suits your needs.
You can simply create a new type that implements Ucommerce.Search.ElasticSearch.IConnectionSettingsProvider
.
To use the Elastic interfaces in the Ucommerce.Search.ElasticSearch namespace, you will have to add a reference to the
\Ucommerce\Apps\bin\Ucommerce.Search.ElasticSearch.dll
to your project. You will also need to install the NEST 7.6.2 nuget package
public class MySpecialSettingsProvider : Ucommerce.Search.ElasticSearch.IConnectionSettingsProvider { public Nest.ConnectionSettings ConnectionSettings { get { //... your implementation here ... return new ConnectionSettings(); } } }
Then register the component in your application specific .config file
<component id="ConnectionSettingsProvider" service="Ucommerce.Search.ElasticSearch.IConnectionSettingsProvider, Ucommerce.Search.ElasticSearch" type="MyWebShop.MySpecialSettingsProvider, MyWebShop"> </component>
To get the implementation part done, you can look at the Elastic.co Connection Pools guide