Showing posts with label Elasticsearch with web8. Show all posts
Showing posts with label Elasticsearch with web8. Show all posts

Saturday, 25 November 2017

Storage Extension Using ElasticSearch and Docker


The latest release of the ElasticSearch4Web8 framework is much more clean, easy in use, less configuration and setup steps are required.To know more about the previous release refer this link.

In the previous version of this framework, apart from CMS and Deployer setup steps, we were required to host custom WCF based Index service, install and configure ElasticSearch. In this release, I've moved all these on Docker.

So, now instead of downloading code host the Index service and ElasticSearch all we need to do is Docker Pull and you will have all the pre-requisites up and running.

Steps to setup latest version of this framework:-
  1. CMS setup
    • Copy and paste the templating building block (TBB) to a location on your SDL WEB 8 CM Server
    • Upload ESI4TIndexing.Templating.dll TBB to WEB 8 CMS using TcmUploadAssembly.exe
    • Create a Component Template with following attributes
      • Output Format – XML Fragment
      • Add GetComponentAsXML TBB ,Publish Binaries in Package, Link Resolver and Cleanup Template.
  2. To setup Elasticsearch run following docker commands.
    • docker pull hemkant/elasticsearch .
    • docker run -p 9200:9200 -m3gb hemkant/elasticsearch
  3. To setup generic, WCF IndexService run following docker commands.
    • docker pull hemkant/elasticsearchintegration4web8 .
    • docker run -p 83:83 hemkant/elasticsearchintegration4web8
  4. To verify all the docker containers are up and running run docker ps command
  5. All these containers are available on hub.docker.com
  6. The last step is setup Deployer service
    • Open the cd_storage_config.xml Storage Configuration file from the /bin/config folder and add following node under the Storages section:
      • <StorageBindings><Bundle src="CustomStorageDAOBundles.xml"/></StorageBindings>
    • Copy and paste CustomStorageConfig.xml file to change the value of following nodes
      • ServiceEndPoint - URL of the IndexService
      • TemplateIdToIndex - Tcm Id Of component Template which we have created in step 1 CMS setup. 
    • Copy the CustomStorageDAOBundles.xml XML file in the Content Delivery /bin/config folder

That's all we need. We have configured the ElasticSearch integration with SDL WEB  now publish the components and data will be stored in ElasticSearch.


Happy coding and keep sharing !!!

Sunday, 16 April 2017

Generic Storage Extension Solution with ElasticSearch,MongoDB and SOLR

In my last couple of blogs we have discussed on how to extend storage capability of SDL WEB 8. Today we are going to create one common solution where we can decide out of the following which one we want to use as a extended storage medium by just updating the configuration file.This will give you the flexability to select the storage medium you wanted to enable.
  1. Elastic Search
  2. MongoDB
  3. SOLR 
  4. You can also use Custom DB.
Let's discuss what is storage extension?

Storage Extension :-Is the capability of using custom storage medium to store the data.When we publish the data it goes in to the BrokerDB or on FileSystem as per the setting but we can extend this functionality by using storage extension technique.

How we do that :-We need to override methods which published and un-published(create,update and remove) component presentation to the Broker DB and need to update the cd_storage_conf.xml file to inject your custom storage extension code.

High-Level GenericStorageExtension Architecture Diagram

You can download the sample code from here

Happy Coding and Keep Sharing !!!!


Wednesday, 22 March 2017

Bypass Model dependency while indexing data in ElasticSearch

Based on the feedback given in SDL Web Dev Summit in Delhi,India.

This is in continuation of my previous blog where we have used ElasticSearch as storage while publishing components data is getting saved in it.

Earlier whenever we need to index any component we first need to create schema model,that creates model based dependency to bypass that we now Serialize the DCP (Dymanic Component preseatation)which is in XML format into JSON and Elastic Search .NET based NEST API has this capability to index JSON directly.

Now, we just need to allow the schema in Dynamic Component Template which we have created to index the data in ElasticSearch.

In NEST API we have used

         var json = @"{
    ""BookName"": ""Book1"",
    ""ISBN"": ""978-3-16-148410-0"",
    ""chapter"" : [
        {
            ""chapter_name"": ""Chapter1"",
            ""chapter_desc"": ""Before getting into computer programming, let us first                     understand computer programs and what they...""
        },
        {
            ""chapter_name"": ""Chapter2"",
            ""chapter_desc"": ""Today computer programs are being used in almost every field,               household, agriculture, medical, entertainment, defense..""
        },
        {
            ""chapter_name"": ""Chapter3"",
            ""chapter_desc"": ""MS Word, MS Excel, Adobe Photoshop, Internet Explorer,                     Chrome, etc., are...""
        },
        {
            ""chapter_name"": ""Chapter4"",
            ""chapter_desc"": ""Computer programs are being used to develop graphics and                   special effects in movie...""
        }
    ]
}";

var indexResponse = client.LowLevel.Index<string>("fromelasticstoweb8", "esnews", json);


And Link Resolver TBB is used to generate the Link e;g i have multimedia component attached ,when you published it will resolve the link below is the DCP XML.


<blog Title='Testing of model' Id='tcm:6-13290' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:tcm='http://www.tridion.com/ContentManager/5.0'>
  <blogTitle>Testing of model</blogTitle>
  <blogDescription>Remove model dependency</blogDescription>
  <image Title='skyline' Id='tcm:6-291' Path='/DigitalAssets/skyline.jpg' xmlns:tridion='http://www.tridion.com/ContentManager/5.0'></image>
  <publication Id='tcm:0-6-1' Title='400 Example Site'></publication></blog>

Happy coding and keep sharing !!!

Tuesday, 28 February 2017

ElasticSearch Module in DXA


In my last two blogs we have discussed how to create components by consuming the data from Elasticsearch and then how to index data in Elasticsearch when publishing components.

Today,We are going to discuss and create Elasticsearch module in DXA which will have following features .DXA Modules allows us to extend its Functionality via creating new modules. Here we can create new modules which gives us flexibility & re-usability.

Features and Advantages :- 

  • Free text search .
  • Tag based filtering.
  • Lighting fast response powered by Elasticsearch.
  • Pagination and sorting based on fields.
  • Article detail page.

In order to use the Elasticsearch module we need to setup the storage extension and Elasticsearch which we already discussed in my previous blog here.
Once that is done using Elasticsearch module in DXA we can search the content from Elasticsearch and render on DXA based application .

Let's discuss the CMS part first.
Elasticsearch Module structure 


  1. Define module's folder structure
  2. DXA gives us predefined structure where we can keep all the building blocks of the module.
  3. For each new DXA module, we need to create a new folder in Modules Folder
  4. The name of folder is usually module name.

Next is creating the Schema and Component Templates. I have create dynamic components and index them in Elasticsearch and render on the DXA based web application.


  1. Publish all the dynamic components and index them in Elastic.
  2. Create new area in you DXA web Application.
    DXA Module
  3. We can call Elastic RESTFul API to get the data.
  4. Data will be returned in the form of JSON.
  5. Create model to deserialize the JSON.
  6. Let's search for the text SDL.
  7. Result can be further filtered based on tagging as well.
  8. Compare the search result with the data index in Elastic
    Elastic Search RESTFul API

.Happy Coding and Keep Sharing !!!

Wednesday, 15 February 2017

ElasticSearch Integration 4 WEB 8


In my previous post we have discussed on how to create components by consuming data from Elastic Search.Today we are going to discuss how to index data in ElasticSearch when publishing components from WEB8.

To know more about the ElasticSearch advantages and how to setup please click here.

Steps to setup Storage extension and Generic Index service which will read data from and push in to the Elastic search.

  1. CMS setup
    • Copy and paste the templating building block (TBB) to a location on your SDL WEB 8 CM Server
    • Upload ESI4TIndexing.Templating.dll TBB to WEB 8 CMS using TcmUploadAssembly.exe
    • Create a Component Template with following attributes
      • Output Format – XML Fragment
      • Add GetComponentAsXML TBB ,Publish Binaries in Package, Link Resolver and Cleanup Template.
  2. Setup ElasticSearch
    • Download ES from here and unzip.
    • Run bin/elasticsearch (or bin\elasticsearch.bat on Windows).
    • Run http://localhost:9200.
    • Default Elasticsearch instance is up and running now.
    • With the help of Elasticsearch .NET high level client ,we can do all the CRUD operations in Elasticsearch.
  3. Setup Deployer service
    • Open the cd_storage_config.xml Storage Configuration file from the /bin/config folder and add following node under the Storages section:
      • <StorageBindings><Bundle src="CustomStorageDAOBundles.xml"/></StorageBindings>
    • Copy and paste CustomStorageConfig.xml file to change the value of following nodes
      • ServiceEndPoint - URL of the IndexService
      • TemplateIdToIndex - Tcm Id Of component Template which we have created in step 1 CMS setup. 
    • Copy the CustomStorageDAOBundles.xml XML file in the Content Delivery /bin/config folder
  4. ElasticSearch Index Service
    • Copy and paste ElasticSearch IndexService on your server host it in IIS 
    • I have used Strongly typed interface to Elasticsearch. Fluent and classic object initializer mappings of requests and responses. Uses and exposes Elasticsearch.Net
    • Run Install-Package NEST
    • Copy the configuration folder as well .
      • You can update the log files path from Logging.config inside the configuration folder
    • Update the path of configuration\logging.config file in web.config of index service
  5. Here, I have created a default index  fromelasticstoweb8 (should be in all lower case other-wise you will get the error Invalid request) and Type esnews.
  6. Once the data is indexed in the ES .
  7. REST service will return data in JSON format.
    • To get all the records http://localhost:9200/fromelasticstoweb8/_search?q=*:*
To test the index and search services
  1. Index service

    1. You can use fiddler for debugging 
    2. I have created a sample schema article
      1. title
      2. description
      3. imageurl
    3. Run index service on fiddler
      • http://localhost/Service1.svc/AddDocument
      • Input JSON which will generated by custom storage 
      • {"ServicePayload":{"DCP":"<esnews Title='About SDL WEB 8' Id='tcm:6-12273' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:tcm='http://www.tridion.com/ContentManager/5.0'><Title>About SDL WEB 8</Title><Description>SDL recently released the latest version of their web content management SDL WEB 8 an all-in-one global Web Experience Management solution</Description><shortTitle>About SDL WEB 8</shortTitle><authorName>SDL</authorName><Category>WEB 8</Category><relasedDate>2017-02-03T23:44:08.261+05:30</relasedDate><imageUrl>Images/SDL.png</imageUrl><publication Id='tcm:0-6-1' Title='400 Example Site'></publication></esnews>","LanguageInRequest":"en"}}Method Name: AddDocument
    4. Execute this request in Fidler and verify the results returned
    5. Check in ElasticSearchas well inside the collection\document which you have created and entered in the index service 
    6. Result as 0 for success and 1 for failure
      •  {"ResponseContext":{"EnvironmentContext":null,"FaultCollection":[]},"ServicePayload":{"ErrorMessage":"","Result":0}}
    7. Test this by publishing the Component as well 
    8. Log File Where Response Result :0 means successfully published and data is index in ElasticSearch.
  2. Search Service
    • To get all data http://localhost:9200/fromelasticstoweb8/_search?q=*:*
    • To get the data based on the title http://localhost:9200/fromelasticstoweb8/esnews/AVo8K0bDJVbTUFCj_OQW
  3. Here fromelasticstoweb8 is the node and esnews is type.
You can download the code here

Happy coding and keep Sharing !!!!

Saturday, 4 February 2017

Connect SDL WEB 8 with Elasticsearch

What is ElasticSearch ?

Elasticsearch is an Apache Lucene-based search server. It was developed by Shay Banon and published in 2010.

Elasticsearch is a real-time distributed and open source full-text search and analytics engine. It is accessible from RESTful web service interface and uses schema less JSON (JavaScript Object Notation) documents to store data. It is built on Java programming language, which enables Elasticsearch to run on different platforms. It enables users to explore very large amount of data at very high speed.


Features of Elasticsearch are as follows:- 
  1. Elasticsearch is scalable up to petabytes of structured and unstructured data.
  2. Elasticsearch is open source and available under the Apache license version 2.0.
  3. Elasticsearch uses denormalization to improve the search performance.
  4. Elasticsearch can be used as a replacement of document stores like MongoDB.
  5. Elasticsearch is one of the popular enterprise search engines, which is currently being used by many big organizations like Wikipedia, The Guardian, StackOverflow, GitHub etc.
key concepts of Elasticsearch:-

Node:- It refers to a single running instance of Elasticsearch. Single physical and virtual server accommodates multiple nodes depending upon the capabilities of their physical resources like RAM, storage and processing power.

Cluster:- It is a collection of one or more nodes. Cluster provides collective indexing and search capabilities across all the nodes for entire data.

Index:- It is a collection of different type of documents and document properties. Index also uses the concept of shards to improve the performance. For example, a set of document contains data of a social networking application.

Type/Mapping:- It is a collection of documents sharing a set of common fields present in the same index. For example, an Index contains data of a social networking application, and then there can be a specific type for user profile data, another type for messaging data and another for comments data.

Replicas:- Elasticsearch allows a user to create replicas of their indexes and shards. Replication not only helps in increasing the availability of data in case of failure, but also improves the performance of searching by carrying out a parallel search operation in these replicas.

Shard:-  Indexes are horizontally subdivided into shards. This means each shard contains all the properties of document, but contains less number of JSON objects than index. The horizontal separation makes shard an independent node, which can be store in any node. Primary shard is the original horizontal part of an index and then these primary shards are replicated into replica shards.


Advantages
Elasticsearch is developed on Java, which makes it compatible on almost every platform.
Elasticsearch is real time, in other words after one second the added document is searchable in this engine.
Elasticsearch is distributed, which makes it easy to scale and integrate in any big organization.
Creating full backups are easy by using the concept of gateway, which is present in Elasticsearch.


Now, Lets create connect  ElasticSearch  and SDL WEB 8 and  components in CMS.

  1. Let's create an console based application using .NET 4.5.
  2. Run the following command in the Package manager console .Install-Package NEST .Install Elasticsearch .NET high level client.
  3. Download Elasticsearch click and unzip the Elasticsearch 
  4. Run ../bin/elasticsearch
  5. Run  http://localhost:9200/
  6. Default Elasticsearch instance is up and running now .
  7. With the help of Elasticsearch .NET high level client ,we can do all the CRUD operations in Elasticsearch.
  8. Here, I have created a default index  fromelasticstoweb8 (should be in all lower case other-wise you will get the error Invalid resquest) and Type esnews.
  9. So the data URL would be  http://localhost:9200/fromelasticstoweb8/esnews/AVoFKrUbqeqnhk6aE3Ca  the last parameter is the ID
  10. To get all the records http://localhost:9200/fromelasticstoweb8/_search?q=*:*
  11. Code snippet to write data in Elasticsearch node
  12. Let read all the data from node fromelasticstoweb8
  13. Using Coreservice we can create components in WEB 8 
    1. Create coreservice client using ISessionAwareCoreService.
    2. Create model Serialize that model into XML.
    3. Using coreservice client.create method we can create the components in WEB 8.
    4. I have created all the items available in ES node fromelasticstoweb8  into SDL WEB 8 as components .
  14. To know more on how to use coreservice to interact with SDL WEB 8 and create CMS items such as components ,Keywords etc you can refer my previous blogs also .


Happy Coding and Keeping Sharing !!!!!