<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kalyan Kumar</title>
    <description>The latest articles on DEV Community by Kalyan Kumar (@kalyants).</description>
    <link>https://dev.to/kalyants</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F860699%2F26108635-bf7c-4f28-a021-88af7d9299de.jpeg</url>
      <title>DEV Community: Kalyan Kumar</title>
      <link>https://dev.to/kalyants</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kalyants"/>
    <language>en</language>
    <item>
      <title>Analyzers in ElasticSearch</title>
      <dc:creator>Kalyan Kumar</dc:creator>
      <pubDate>Fri, 20 May 2022 17:44:28 +0000</pubDate>
      <link>https://dev.to/kalyants/analyzers-in-elasticsearch-1pbi</link>
      <guid>https://dev.to/kalyants/analyzers-in-elasticsearch-1pbi</guid>
      <description>&lt;p&gt;It is important to understand how analyzers in ElasticSearch work to have an appropriate indexing strategy for your use-case. If you don’t choose a suitable indexing strategy, it would become complex to write queries for your use-case and the queries could end up being slow.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an analyzer?
&lt;/h2&gt;

&lt;p&gt;We can think of it as a pipeline. When a document is indexed in ElasticSearch, the string data of the document is given input to the pipeline and an output of terms is generated. These terms are then reverse indexed (as discussed in the previous blog).&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WG0Fevy4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vxp4z2qgmz6uzsidjwks.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WG0Fevy4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vxp4z2qgmz6uzsidjwks.png" alt="Analyzer pipeline" width="880" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is this pipeline made of?
&lt;/h2&gt;

&lt;p&gt;This algorithmic pipeline contains 3 components.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Character filter&lt;/li&gt;
&lt;li&gt;Tokenizer&lt;/li&gt;
&lt;li&gt;Token filter&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each component does some specific operation on the string data and outputs it to the next component. Let’s discuss in brief what these components individually do:&lt;/p&gt;

&lt;h3&gt;
  
  
  Character filter
&lt;/h3&gt;

&lt;p&gt;This component can add, remove or modify the characters present in the string.&lt;/p&gt;

&lt;p&gt;Let’s understand this through an example below.&lt;/p&gt;

&lt;p&gt;HTML strip character filter:&lt;/p&gt;

&lt;p&gt;Think of a use-case where you are storing html file contents as string data in ElasticSearch. This filter can remove all the HTML tags like &lt;code&gt;&amp;lt;b&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; from the input string data.&lt;br&gt;
Example:&lt;br&gt;
&lt;code&gt;&amp;lt;p&amp;gt;Ironman is flying&amp;lt;p&amp;gt;&lt;/code&gt; would be modified to &lt;code&gt;Ironman is flying&lt;/code&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6-vFUnBu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pemm228egxvplckoyydv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6-vFUnBu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pemm228egxvplckoyydv.png" alt="Character filter" width="880" height="648"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The modified string is then passed as input to the tokenizer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tokenizer
&lt;/h3&gt;

&lt;p&gt;A tokenizer takes a string and breaks it into multiple tokens. The logic based on which the string is broken down into tokens depends on the type of tokenizer you are using.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J81RRvGE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rco2xgdt2e8lrvsd7ovm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J81RRvGE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rco2xgdt2e8lrvsd7ovm.png" alt="Tokenizer" width="880" height="607"&gt;&lt;/a&gt;&lt;br&gt;
For example, a Whitespace Tokenizer would split the string whenever it encounters a whitespace in the string. &lt;code&gt;Ironman is flying&lt;/code&gt; would result in tokens: [&lt;code&gt;Ironman&lt;/code&gt;, &lt;code&gt;is&lt;/code&gt;, &lt;code&gt;flying&lt;/code&gt;]&lt;/p&gt;

&lt;p&gt;The output list of tokens are then passed to the token filter.&lt;/p&gt;

&lt;h3&gt;
  
  
  Token filter
&lt;/h3&gt;

&lt;p&gt;This component adds, modifies or filters out the individual tokens generated in the previous step.&lt;/p&gt;

&lt;p&gt;Let’s consider Edge-ngram token filter. This token filter takes each token and produces all the possible prefix substrings of the token.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TD9odgSi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/erfdgqfgrfmxcqui3dll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TD9odgSi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/erfdgqfgrfmxcqui3dll.png" alt="Token filter" width="880" height="648"&gt;&lt;/a&gt;&lt;br&gt;
[&lt;code&gt;Ironman&lt;/code&gt;, &lt;code&gt;is&lt;/code&gt;, &lt;code&gt;flying&lt;/code&gt;] would generate following tokens:&lt;/p&gt;

&lt;p&gt;[ &lt;code&gt;I&lt;/code&gt;, &lt;code&gt;Ir&lt;/code&gt;, &lt;code&gt;Iro&lt;/code&gt;, &lt;code&gt;Iron&lt;/code&gt;, &lt;code&gt;Ironm&lt;/code&gt;, &lt;code&gt;Ironma&lt;/code&gt;, &lt;code&gt;Ironman&lt;/code&gt;, &lt;code&gt;i&lt;/code&gt;, &lt;code&gt;is&lt;/code&gt;, &lt;code&gt;f&lt;/code&gt;, &lt;code&gt;fl&lt;/code&gt;, &lt;code&gt;fly&lt;/code&gt;, &lt;code&gt;flyi&lt;/code&gt;, &lt;code&gt;flyin&lt;/code&gt;, &lt;code&gt;flying&lt;/code&gt;]&lt;/p&gt;

&lt;p&gt;Note: The example presented here is very specific. There are many types of Tokenizers, Token filters and Character filters to use. You can construct a custom analyzer specific to your use-case.&lt;/p&gt;

</description>
      <category>elasticsearch</category>
      <category>database</category>
      <category>beginners</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>How does ElasticSearch work?</title>
      <dc:creator>Kalyan Kumar</dc:creator>
      <pubDate>Wed, 11 May 2022 04:13:18 +0000</pubDate>
      <link>https://dev.to/kalyants/how-does-elasticsearch-work-1047</link>
      <guid>https://dev.to/kalyants/how-does-elasticsearch-work-1047</guid>
      <description>&lt;p&gt;ElasticSearch is a search engine technology used by many companies for use-cases like: full-text search, autocomplete suggestions, data analytics, etc.&lt;/p&gt;

&lt;p&gt;It is a document-oriented database. The high level architecture of ElasticSearch is as follows (bottom-up):&lt;/p&gt;

&lt;h2&gt;
  
  
  Document
&lt;/h2&gt;

&lt;p&gt;Documents are the basic units of information you can store in ElasticSearch. You store the data in the form of a JSON document. Every document has a unique ID which is used for reverse indexing the data (discussed at the end).&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ofbkuIqU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qz9c8kufgn0pnvgq1rns.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ofbkuIqU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qz9c8kufgn0pnvgq1rns.png" alt="Image description" width="786" height="510"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;p&gt;An index is a collection of the similar type documents. An index is analogous to the database in relational databases. When you query in ElasticSearch, you query against a particular index.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gPGHAf10--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sblf4pg73vhhbfl2lu8e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gPGHAf10--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sblf4pg73vhhbfl2lu8e.png" alt="Image description" width="880" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Node and Cluster
&lt;/h2&gt;

&lt;p&gt;An ElasticSearch cluster is a collection of nodes connected together.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bxVkX-mg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2pgaa1fq6feit8lvgulk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bxVkX-mg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2pgaa1fq6feit8lvgulk.png" alt="Image description" width="880" height="515"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Shard
&lt;/h2&gt;

&lt;p&gt;It is not necessary that an index in ElasticSearch cluster need to be present only on a single node. It could be broken down into parts and shared among multiple nodes to achieve horizontal scalability. Each part of an index present on a node is called a Shard.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RRoRfUOr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2wlso1elavawtbzezxy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RRoRfUOr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2wlso1elavawtbzezxy.png" alt="Image description" width="880" height="468"&gt;&lt;/a&gt;&lt;br&gt;
users index has 10k documents which are shared between node1 and node2. Each part of 5k documents is called a shard.&lt;/p&gt;

&lt;p&gt;Now that we understand high level architecture of ElasticSearch, let's have a look at how it internally works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reverse Indexing
&lt;/h2&gt;

&lt;p&gt;ElasticSearch uses a special data structure called reverse index. Every term in the data is indexed against the document IDs of documents containing the term.&lt;br&gt;
Let's understand this through an example below:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ayWeJ7rQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vu7t4kd8fy5o2ghlceq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ayWeJ7rQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vu7t4kd8fy5o2ghlceq.png" alt="Image description" width="880" height="716"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Consider 2 documents as stated above with IDs: 1 and 2. When these documents are indexed(loaded into the index), every term from the document is taken and it is mapped to the document ID. When you query for a certain term, it is like a lookup in the dictionary. This is what primarily makes ElasticSearch very fast.&lt;/p&gt;

&lt;p&gt;More articles to follow in this series of ElasticSearch articles. Please comment down if you want me to write an article about a specific topic.&lt;/p&gt;

</description>
      <category>elasticsearch</category>
      <category>database</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
