<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Musab Dogan on Medium]]></title>
        <description><![CDATA[Stories by Musab Dogan on Medium]]></description>
        <link>https://medium.com/@musabdogan?source=rss-7692320510b5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*KXjrB-w4LokcrfX3</url>
            <title>Stories by Musab Dogan on Medium</title>
            <link>https://medium.com/@musabdogan?source=rss-7692320510b5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 05:59:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@musabdogan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[We Tested PGSync for Postgres → OpenSearch Sync. We Didn’t Ship It.]]></title>
            <link>https://medium.com/@musabdogan/we-tested-pgsync-for-postgres-opensearch-sync-we-didnt-ship-it-5c2eb977918d?source=rss-7692320510b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c2eb977918d</guid>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[opensearch]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[pgsync]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Musab Dogan]]></dc:creator>
            <pubDate>Thu, 15 Oct 2026 09:26:37 GMT</pubDate>
            <atom:updated>2026-10-15T09:26:37.571Z</atom:updated>
            <content:encoded><![CDATA[<p>PGSync is a good tool. This is not a takedown. It’s an account of why it didn’t fit our setup, in case yours looks like ours.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKrgSCb8UjQ11wRjFcoNEw.png" /></figure><h3>The setup</h3><p>We keep a search index in OpenSearch, fed from an Aurora Postgres database. The existing pipeline was polling: scheduled Lambdas run SQL functions that build denormalized documents and push them to the index. It works, but it is not real time and it is not elegant.</p><p>PGSync promised the opposite: read the WAL through logical replication, stream every change, no polling. We spent weeks on it: staging, a develop environment, seven indexes, parity checks against production mappings. Then we cancelled it.</p><h3>What worked</h3><p>To be fair: it worked. Backfills were fast (about 19 seconds for six small indexes), document counts matched Postgres exactly, and CDC lag was around 17 seconds. If your documents are a straightforward tree of joined tables, PGSync is genuinely good.</p><h3>Why it didn’t fit</h3><p>1. One process, many threads, silent failure. With several indexes, PGSync runs them as threads inside a single process. One night, a 60-second OpenSearch read timeout killed one thread. The process stayed alive, so the container showed “Up” and restart: always never fired. The replication slot sat inactive and Postgres kept every WAL segment for it. We found 131 GB of retained WAL on a sandbox database days later. Nothing paged us, because nothing was technically down.</p><p>The only reliable health check we found was querying pg_replication_slots for active = false. PGSync has no health endpoint, so you build the monitoring yourself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bi3OG8oLMs8qO79n0yFkrg.png" /></figure><p>2. One slot per index. Each index needs its own replication slot, and each slot decodes the whole WAL independently. Six indexes means six decoders. We wanted some indexes refreshed on a schedule without a slot. The code doesn’t allow it: no slot, RuntimeError.</p><p>3. Cascades are expensive, and fan-out is real. When a non-root table changes, PGSync asks OpenSearch which documents are affected and rebuilds them. That’s elegant until one row touches millions of documents. In our data, a single processors row was referenced by about 19 million payments. At the roughly 1,000 documents/second we measured, that&#39;s around 5 hours during which the slot doesn&#39;t advance.</p><p>We found a workaround, disabling _meta.&lt;table&gt; in the index mapping. We proved it with a control experiment: touching a processor row changed nothing, touching a customer row bumped a version in 17 seconds. But now correctness depends on a mapping flag nobody will remember. The trade-off is easy to get wrong when the next person edits the template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qudVeN-1f39AUHj5ML0jlQ.png" /></figure><p>4. Our documents weren’t just joins. The real pipeline did more than join tables. It derived fields: a last4 that only exists for card payments, plan fields flattened and renamed from the subscription&#39;s own plan version, not the latest one, and one id that is a prefixed id in one index and a UUID in another. None of this is expressible in PGSync&#39;s schema, so it moved into OpenSearch ingest pipelines. We were rebuilding behavior we had to reverse-engineer from SQL functions, and I&#39;ll admit I got it wrong several times before reading the code instead of comparing output.</p><p>5. Production prerequisites. Production ran wal_level = replica, not logical. Changing it means a reboot. Not impossible, but one more reason the migration was a project and not a switch.</p><p>6. Sharp edges that cost days:</p><ul><li>--bootstrap is destructive: it drops the slot and deletes the checkpoint.</li><li>Backfill is incremental after the first run. Delete an index without deleting its checkpoint file and it silently stays empty, exit code 0.</li><li>_cat/indices counts nested documents, so a parity check using it was off by 2x.</li><li>On the machine we tested, forgetting one of three steps (bootstrap, backfill, daemon) silently loads no history.</li></ul><h3>What we chose instead</h3><p>We kept the Lambda polling pipeline. Not because it is better technology, but because the team already understands it, it is one place to look when it breaks, and its failures are loud. PGSync’s were quiet.</p><h3>The honest takeaway</h3><ul><li>A real-time pipeline is not just a tool. It’s a monitoring problem, a recovery problem and a runbook.</li><li>“It works in staging” told us little. Our problems showed up with long-running processes and large fan-out.</li><li>Silent failure is the worst failure mode for sync. Ask any tool: <em>how will I know when you stop?</em></li><li>Sustainability beat elegance. The boring option the team can operate won.</li></ul><p>If your indexes are few, your documents are simple trees, and you can monitor slots, try PGSync. We’d have been happy with it in a smaller setup.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c2eb977918d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Elasticsearch Misconfiguration Your Cluster Health API Will Never Tell You About]]></title>
            <link>https://medium.com/@musabdogan/the-elasticsearch-misconfiguration-your-cluster-health-api-will-never-tell-you-about-87b8a127f42c?source=rss-7692320510b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/87b8a127f42c</guid>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[monitoring]]></category>
            <dc:creator><![CDATA[Musab Dogan]]></dc:creator>
            <pubDate>Mon, 24 Aug 2026 08:01:02 GMT</pubDate>
            <atom:updated>2026-08-24T08:01:02.942Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7izfCGngi0VTon_B6ptUlA.png" /></figure><h3>Elastic101 — Best Practice #001</h3><p><em>Your cluster is green. Your dashboards are clean. And half your application traffic might be landing on the three nodes that can least afford it.</em></p><p>I’ve spent almost ten years working with Elasticsearch — six of them consulting, four training teams on the stack. In that time I’ve audited a lot of production clusters, and I’ve noticed that the same handful of mistakes keep showing up in companies that have never spoken to each other.</p><p>This series is about those mistakes. One per post, short enough for a coffee break, specific enough that you can go check your own cluster afterwards.</p><p>Let’s start with the one I find most often — and the one that hides the best.</p><h3>The rule</h3><p><strong>Send all HTTP traffic to coordinating-only nodes.</strong></p><p>If your cluster has no dedicated coordinating-only nodes, send it to data nodes instead.</p><p>Either way: <strong>not to your master nodes.</strong></p><h3>Where the misconception comes from</h3><p>Nobody does this out of carelessness. They do it because of a mental model imported from somewhere else — usually Kubernetes.</p><p>In Kubernetes, the control plane exposes a central API endpoint. kubectl talks to the API server. Your tooling talks to the API server. The control plane <em>is</em> the front door; pointing everything at it isn&#39;t a mistake, it&#39;s the design.</p><p>Elasticsearch does not work this way. The word “master” carries intuitive weight — it sounds like the node in charge, the one you should be addressing. But a master node is closer to a cluster bookkeeper than an API gateway. Its job is maintaining and publishing cluster state: which indices exist, where shards live, which nodes are present, what happens when one disappears.</p><p>None of that has anything to do with serving your application’s search requests.</p><p><strong>Master ≠ API server.</strong></p><h3>Why it hurts — and why you won’t notice</h3><p>Here’s what makes this one worth writing about.</p><p><strong>Nothing breaks immediately.</strong> Every Elasticsearch node accepts HTTP and routes requests, master nodes included. Point your application at a master and it works. Queries return. Dashboards load. The logs stay quiet.</p><p>The damage shows up later, under load, disguised as something else.</p><p>When a node coordinates a request it does real work: parsing, fanning out to shards, and — the expensive part — running the <strong>reduce phase</strong>, merging partial results from every shard into a final response. A heavy aggregation can allocate a lot of heap in a very short window.</p><p>Now put that on the elected master. The same JVM responsible for publishing cluster state is busy merging aggregation buckets and fighting GC pauses. State publication is delayed. Node join and leave events take longer. Push hard enough and followers start timing out on the master — worst case, an unnecessary election, during which your cluster can’t make any structural change at all.</p><p>The failure mode is asymmetric, and that asymmetry is the whole argument:</p><ul><li>A <strong>coordinating node</strong> that exhausts heap under a heavy aggregation is one node having a bad day. Requests fail, it recovers, life goes on.</li><li>A <strong>master node</strong> that exhausts heap under the same aggregation is the entire cluster having a bad day.</li></ul><p>You’re taking your spikiest, least predictable workload — user queries — and placing it on the one node everything else depends on for stability.</p><p><strong>And here’s the part that keeps this alive in production for years:</strong> there is no metric for it. _cluster/health returns green. Your node CPU graphs look normal. There is no dashboard panel called &quot;application traffic hitting master nodes.&quot; It isn&#39;t a number you can alert on — it&#39;s a <em>shape</em>, and you only find it if you go looking for the shape.</p><h3>What the shape looks like</h3><p>This is a real 33-node production cluster, seen through the traffic map in <a href="https://chromewebstore.google.com/detail/elasticsearch-performance/eoigdegnoepbfnlijibjhdhmepednmdi">Searchali</a> — a tool I built precisely because this class of problem is invisible in standard monitoring.</p><p>Client traffic lands on the coordinating tier and fans out to the data nodes. The master block at the top has nothing pointing at it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x_JZCU75-ZD1kXPUJT0MRg.png" /><figcaption>Caption: A healthy topology in Searchali’s traffic map. Client connections terminate on the coordinating tier; the master nodes stay quiet.</figcaption></figure><p>And this is the same cluster with the problem. Look at the top block — traffic lines now reach the master nodes directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2dfLwip_TTJK2Ad17mG51w.png" /><figcaption>Same cluster. Same node count. Still GREEN. But application traffic is now hitting the masters — the one thing no health check will report.</figcaption></figure><p>Same 33 nodes, same green status, same 16.2 billion documents. The only difference is where the lines end, and that difference is the entire problem.</p><h3>Check your own cluster in about ten seconds</h3><p>I’d genuinely encourage you to look, because the answer surprises people more often than you’d expect. Configuration drifts. Someone hardcodes a hostname during a 3am incident and it never gets cleaned up. Service discovery builds an endpoint list from “all nodes in the cluster” and cheerfully includes the masters.</p><p><strong>The fast way.</strong> Install the <a href="https://chromewebstore.google.com/detail/elasticsearch-performance/eoigdegnoepbfnlijibjhdhmepednmdi">Searchali Chrome extension</a>, point it at your cluster, and open the Traffic tab. The connection is made directly from your browser — no agent, nothing installed server-side, nothing to deploy or get approved. The traffic map groups your nodes by role and draws a line for every active client, so the question “is anything hitting my masters?” becomes a thing you <em>see</em> rather than a thing you calculate.</p><p><strong>The manual way,</strong> if you’d rather stay in the console. Two calls:</p><pre>GET _cat/nodes?v&amp;h=name,ip,node.role,master</pre><p>In node.role, m is master-eligible, d is data, i is ingest, and a bare - means no roles at all — a coordinating-only node. The master column marks the elected master with *. Nodes showing only m are your dedicated masters; write those names down.</p><pre>GET _nodes/stats/http</pre><p>This returns http.current_open and http.total_opened per node. Cross-reference against your list. On a correctly configured cluster, dedicated masters should show a total_opened count that&#39;s low and essentially static — a trickle from monitoring agents and the occasional admin curl. If a master&#39;s counter climbs anywhere near the rate of your data nodes, you&#39;ve found traffic that shouldn&#39;t be there.</p><p>The manual method tells you <em>whether</em> it’s happening. It won’t tell you <em>which client</em>, <em>which agent</em>, or <em>which network</em> — which is what you actually need in order to fix it, and the reason the visual view exists.</p><h3>How to fix it</h3><p>One important subtlety, and it’s where most people get it wrong on the second attempt.</p><p><strong>You cannot turn this off on the master node itself.</strong> Elastic’s documentation is explicit: master-eligible nodes will still behave as coordinating nodes routing client requests, and there is no setting to disable that. (If you’ve read older guides suggesting http.enabled: false — that was deprecated in 6.3 and removed in 7.0. It isn&#39;t an option anymore.)</p><p>So the fix lives entirely at the client and load balancer layer:</p><p><strong>Point your clients at the right nodes.</strong> Whatever sits in front of the cluster — load balancer pool, service definition, a hardcoded seed list in application config — it should contain only coordinating-only nodes, or only data nodes. Never a master.</p><p><strong>Define coordinating-only nodes explicitly.</strong> On 7.9 and later, an empty roles array:</p><pre>node.roles: [ ]</pre><p>On older versions, turn each role off individually:</p><pre>node.master: false<br>node.data: false<br>node.ingest: false</pre><p>A coordinating-only node joins the cluster and receives full cluster state like any other node, but holds no data and takes no master duties. It’s a smart load balancer that speaks Elasticsearch natively — it knows exactly which shards live where, so it routes directly instead of guessing.</p><p><strong>Audit the list that generates your endpoints,</strong> and filter by role rather than by cluster membership.</p><p><strong>Then verify.</strong> This is the step people skip, and it’s why the problem comes back. After you’ve changed the load balancer config, look at the traffic map again — you want to see the lines move off the master block and stay off. A config change you didn’t confirm at the traffic layer is a config change you’re assuming worked.</p><h3>Do you actually need coordinating-only nodes?</h3><p>Not necessarily, and I’d push back on advice that treats them as mandatory.</p><p>My rule of thumb: <strong>under about 20 nodes, adding another data node usually beats adding a dedicated coordinating node.</strong> You get coordination capacity <em>and</em> storage and indexing capacity for the same hardware, instead of a node that only does one job.</p><p>Coordinating-only nodes start earning their keep when coordination itself becomes the bottleneck — large aggregations, deep pagination, heavy msearch batches, where the reduce phase is genuinely expensive and worth isolating from the nodes doing shard work.</p><p>The honest version:</p><ul><li><strong>Under ~20 nodes, no heavy aggregations:</strong> send traffic to data nodes. Skip the coordinating tier.</li><li><strong>Larger clusters, or expensive query patterns:</strong> add coordinating-only nodes and send traffic there.</li><li><strong>In every case:</strong> not the masters.</li></ul><p>That last line has no exceptions.</p><h3>What else the traffic view tells you</h3><p>Once you can see traffic per client rather than per node, a few other questions get much easier to answer — and these are the ones that usually come up next in an audit:</p><ul><li><strong>Which client IP is responsible for a load spike.</strong> The map breaks traffic down by client IP, not just by node, so “something is hammering the cluster” becomes a specific address.</li><li><strong>What kind of load it is.</strong> Search, index, update and delete operations are distinguished, so you can tell a read spike from a bulk indexing run at a glance.</li><li><strong>Which agent is talking.</strong> Beats, the official Elastic clients, raw Java clients — knowing what’s connecting is half of tracking down an owner for it.</li><li><strong>Which networks your traffic comes from.</strong> Grouping by network segment surfaces the connections nobody remembers configuring.</li><li><strong>Which clients have gone quiet.</strong> An application that stopped talking to the cluster is often more interesting than one that’s talking too much.</li></ul><p>None of that requires deploying anything. It runs in the browser, against your cluster, and you can uninstall it in one click if it isn’t useful.</p><p><a href="https://chromewebstore.google.com/detail/elasticsearch-performance/eoigdegnoepbfnlijibjhdhmepednmdi"><strong>Try it on your own cluster →</strong></a></p><p><a href="https://chromewebstore.google.com/detail/elasticsearch-performance/eoigdegnoepbfnlijibjhdhmepednmdi">Elasticsearch Performance Monitoring - Chrome Web Store</a></p><h3>Recap</h3><ol><li>Master nodes manage cluster state. They’re not an API gateway, and the Kubernetes intuition doesn’t transfer.</li><li>Coordination work — especially the aggregation reduce phase — competes with cluster state management for heap and CPU in the same JVM.</li><li>A coordinating node under pressure degrades one node. A master node under pressure degrades everything.</li><li>No health check reports this. It’s a shape in your traffic, not a number on a dashboard.</li><li>You can’t disable coordination on a master — fix it at the client and load balancer layer, then verify at the traffic layer.</li><li>Under ~20 nodes, data nodes are usually a better traffic target than a dedicated coordinating tier.</li></ol><p>Go look at where your traffic actually lands. If the answer is boring, that’s a good outcome — and it takes about a minute to find out.</p><p><em>This is #001 in the Elastic101 series — short, practical notes on the Elasticsearch problems I keep running into in production. Next: shard sizing, and why “more shards” is almost never the answer. Follow to catch the rest.</em></p><p><strong>About</strong> — I’m an Elasticsearch consultant and trainer. <a href="https://searchali.com/">searchali.com</a> is an official Elastic Partner. We do cluster health audits, performance and cost tuning, OpenSearch migrations and upgrades, and hands-on training for engineering teams. <a href="https://chromewebstore.google.com/detail/elasticsearch-performance/eoigdegnoepbfnlijibjhdhmepednmdi">Searchali Elasticsearch Monitoring</a> is the free browser extension behind the screenshots in this post.</p><p><em>Seeing a different failure pattern in your own clusters, or disagree with the 20-node threshold? Tell me in the comments I read all of them, and the disagreements are usually where the interesting cases are.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87b8a127f42c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Cut Elasticsearch Costs with Field Usage Stats API call(And Automate It in 2 Clicks)]]></title>
            <link>https://medium.com/@musabdogan/how-to-cut-elasticsearch-costs-with-field-usage-stats-api-call-and-automate-it-in-2-clicks-57f4261cc225?source=rss-7692320510b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/57f4261cc225</guid>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[cost-optimization]]></category>
            <category><![CDATA[opensearch]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <dc:creator><![CDATA[Musab Dogan]]></dc:creator>
            <pubDate>Tue, 10 Mar 2026 11:01:01 GMT</pubDate>
            <atom:updated>2026-03-10T11:01:01.371Z</atom:updated>
            <content:encoded><![CDATA[<p>Unsearched fields waste storage, memory, and CPU. Use Elasticsearch’s field usage stats and a free Chrome extension to find them and reduce cluster cost</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*whHpoMluG7xtvFvCDYl4nw.png" /><figcaption>Cluster overview + Indices tab with list of indices, columns: Index, Field count, Unsearched fields, Most used field.</figcaption></figure><p><a href="https://chromewebstore.google.com/detail/elasticsearch-performance/eoigdegnoepbfnlijibjhdhmepednmdi">Elasticsearch Performance Monitoring - Chrome Web Store</a></p><h3>Why Unsearched Fields Cost You More Than You Think</h3><p>If you run Elasticsearch in production, you care about cost: disk, heap, and CPU. One of the easiest levers is field usage. Every field in your mapping is stored and indexed. Fields that are never used in search, sort, or aggregation still consume:</p><ul><li>Storage — inverted index, doc_values, and stored data</li><li>Memory — segment cache, field data cache</li><li>CPU — indexing and occasional background work</li></ul><p>The more unused fields, the more you pay and the slower things get. The fix is simple in theory: find them and remove or relax their indexing. In practice, that used to mean custom scripts or one-off queries. Not anymore.</p><h3>What Elasticsearch Tells You: Field Usage Stats</h3><p>From Elasticsearch 7.15+, the Field Usage Stats API (GET _field_usage_stats) tells you exactly which fields are used and how:</p><ul><li>Search — used in query (inverted index)</li><li>Sort &amp; Agg — used in sorting/aggregations (doc_values)</li><li>Range query, stored, scoring, etc.</li></ul><p>Official link: <a href="https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-field-usage-stats">https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-field-usage-stats</a></p><blockquote>Field usage statistics are automatically captured when queries are running on a cluster. A shard-level search request that accesses a given field, even if multiple times during that request, is counted as a single use.</blockquote><p>If a field has zero usage across all these dimensions, it’s unsearched: it’s only been returned in _source or in hits, never in a query. Those are prime candidates for cost optimization: you can drop them from the mapping on reindex or stop indexing them in new indices.</p><p>Manually calling the API per index and merging with mapping data is tedious. That’s where automation helps.</p><h3>Automating It with the Elasticsearch Performance Monitoring Chrome Extension</h3><p>The Elasticsearch Performance Monitoring Chrome extension connects to your cluster (with your credentials, nothing leaves your network) and surfaces field usage in one place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*trxXbNezKAKrjUZEnTt6MQ.png" /><figcaption>Index detail popover with “Total: 136 Used: 8 Unsearched: 128”, field list with Usage and Usage type columns.</figcaption></figure><p>In the Indices tab you get:</p><ul><li>A list of all indices with field count, unsearched field count, and most used field</li><li>Sort and filter so you can quickly see indices with the most unsearched fields</li><li>One click on an index opens the detailed field usage view</li></ul><p>So instead of scripting _field_usage_stats and _mapping for every index, you get a single dashboard that answers: <em>“Where am I indexing fields that nobody queries?”</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qGafea7CM1cB4MOjmFmmXw.png" /></figure><p>In the index detail view you see:</p><ul><li>Total / Used / Unsearched — e.g. 136 total, 8 used, 128 unsearched</li><li>A per-field table with usage (e.g. “34 docs”) and usage type (Search, Sort &amp; Agg, Range query, etc.)</li><li>Which field is most used (often @timestamp in time-series indices)</li></ul><p>That’s exactly the data you need to decide what to keep and what to drop. No CSV exports, no ad‑hoc scripts — just point the extension at your cluster and use the UI.</p><h3>How This Turns Into Cost Savings</h3><ol><li>Identify — In the extension, sort indices by unsearched field count and open the worst offenders (e.g. 128 unsearched out of 136).</li><li>Decide — For each unsearched field: remove from mapping on next reindex, or set index: false / adjust doc_values if you still need them in _source.</li><li>Reindex — Create a new index with the trimmed mapping and reindex. Old index can be deleted after cutover.</li><li>Repeat — Use the extension regularly (e.g. after schema or ingest changes) to keep unsearched growth under control.</li></ol><p>Result: less disk, less heap, and often better indexing and search latency. The exact savings depend on how many fields you remove and how big the indices are, but the direction is always the same — fewer unused structures, lower cost.</p><h3>Who This Is For</h3><p>This workflow is aimed at Elasticsearch developers, DevOps, and backend engineers who already manage clusters and want to:</p><ul><li>Reduce storage and memory without changing application behavior</li><li>Avoid writing and maintaining custom tooling for field usage</li><li>Get a quick, visual view of “where is my mapping bloated?” across many indices</li></ul><p>The extension uses the same APIs you’d use in scripts (e.g. _field_usage_stats, _cat/indices, _mapping); it just automates the calls and puts the results in one UI.</p><h3>Summary</h3><ul><li>Unsearched fields increase cost (disk, memory, CPU) and add no query value.</li><li>Field Usage Stats (ES 7.15+) show which fields are used and how.</li><li><a href="https://chromewebstore.google.com/detail/elasticsearch-performance/eoigdegnoepbfnlijibjhdhmepednmdi">The Elasticsearch Performance Monitoring Chrome extension</a> turns that into a ready-to-use Indices view: unsearched counts per index and per-field usage in one click.</li><li>Use it to find and trim unused fields, reindex, and repeat — so you keep cluster cost and complexity under control without extra scripting.</li></ul><p>Thanks for reading. Check it out my other articles related to Elasticsearch and Opensearch below.</p><p><a href="https://medium.com/@musabdogan">Musab Dogan - Medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57f4261cc225" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elasticsearch Indexing Rate and Search Latency Monitoring From Your Browser: A Chrome Extension]]></title>
            <link>https://medium.com/@musabdogan/elasticsearch-indexing-rate-and-search-latency-monitoring-from-your-browser-a-chrome-extension-b0832791c3be?source=rss-7692320510b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0832791c3be</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[elk-stack]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[opensearch]]></category>
            <dc:creator><![CDATA[Musab Dogan]]></dc:creator>
            <pubDate>Mon, 16 Feb 2026 09:57:58 GMT</pubDate>
            <atom:updated>2026-02-16T10:00:32.803Z</atom:updated>
            <content:encoded><![CDATA[<h3>Real-Time Elasticsearch Indexing Rate and Search Latency Monitoring From Your Browser: A Chrome Extension</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dkrOIrEIuxt5XiKUjAZ0Rg.jpeg" /><figcaption>How we built a lightweight dashboard to track cluster health, indexing/search rates, and node metrics without opening Kibana.</figcaption></figure><p><a href="https://chromewebstore.google.com/detail/elasticsearch-performance/eoigdegnoepbfnlijibjhdhmepednmdi">Elasticsearch Performance Monitoring - Chrome Web Store</a></p><h3>Why we built it</h3><p>Keeping an eye on Elasticsearch clusters usually means Kibana, Grafana, or custom backends. They’re powerful, but sometimes you only need a quick look: Is the cluster green? Are indexing and search rates normal? Which indices or nodes are under load?</p><p>We wanted that view one click away, without logging into a separate app or setting up a proxy. So we built a Chrome extension that talks directly to Elasticsearch and shows a real-time monitoring dashboard in a new tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EkQqyIi0IH3bwTlJDnTq5g.png" /></figure><h3>What it does</h3><p>Elasticsearch Performance Monitoring is a browser extension that:</p><ul><li>Connects directly to your cluster (URL + optional credentials). No proxy or backend; the extension calls the Elasticsearch APIs from the browser.</li><li>Shows live metrics: indexing rate (ops/sec), search rate (ops/sec), index and search latency, with simple charts and sparklines.</li><li>Surfaces cluster resources: CPU, JVM heap, and storage usage so you can spot pressure quickly.</li><li>Lets you drill down: index list (size, doc count, shards) and node list (roles, IPs) with search and filters.</li><li>Supports multiple clusters: add several clusters and switch between them from the same dashboard.</li></ul><p>All of this is in a single tab, with a minimal UI focused on the numbers that matter for day-to-day ops.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6lzm_toOmvvJflOlRhwUpA.jpeg" /></figure><h3>Security: use a dedicated monitoring user</h3><p>Using the elastic superuser for a dashboard is not a good idea. The extension is designed to work with a read-only monitoring user.</p><p>We recommend creating a user with the built-in remote_monitoring_collector role. That role has the minimum privileges needed for cluster health, node stats, and index metrics — ideal for a monitoring dashboard. You can create the user via Kibana Dev Tools or with a curl call; the in-app “Dedicated Monitoring User (optional)” tab describes both options and links to the official roles documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X7JcdZ4aNJtJyeSaMoCVQA.jpeg" /></figure><h3>Under the hood</h3><p>The extension uses the same APIs you’d use in scripts or Kibana: /_cluster/health, /_cat/nodes, /_cat/indices, /_stats, /_nodes/stats, with filter_path where it helps to keep responses small. The front end is React and TypeScript, with Recharts for charts and Tailwind CSS for layout. Build is Vite; the packaged app runs as a Manifest V3 Chrome extension with a minimal permission set: storage for cluster configs and &lt;all_urls&gt; so it can call your cluster URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TCFovL5pREjbAmkJ7XJGaA.jpeg" /></figure><h3>Try it</h3><p>If you run Elasticsearch (or Elastic Cloud) and want a quick way to check cluster health and performance from the browser, you can install Elasticsearch Performance Monitoring here:</p><p>Install from Chrome Web Store: <a href="https://chromewebstore.google.com/detail/elasticsearch-performance/eoigdegnoepbfnlijibjhdhmepednmdi">https://chromewebstore.google.com/detail/elasticsearch-performance/eoigdegnoepbfnlijibjhdhmepednmdi</a></p><p>Source code (MIT): GitHub — elasticsearch-performance-monitoring (<a href="https://github.com/musabdogan/elasticsearch-performance-monitoring">https://github.com/musabdogan/elasticsearch-performance-monitoring</a>).</p><p>Summary: A Chrome extension that gives you real-time Elasticsearch monitoring (health, indexing/search rates, latencies, index and node stats) in a new tab, with optional guidance for using a dedicated read-only monitoring user and links to official docs</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0832791c3be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elasticsearch notification with ElastAlert - flatline guide]]></title>
            <link>https://medium.com/@musabdogan/elasticsearch-notification-with-elastalert-flatline-guide-f6909c932598?source=rss-7692320510b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6909c932598</guid>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[elastalert]]></category>
            <category><![CDATA[opensearch]]></category>
            <category><![CDATA[alerts]]></category>
            <category><![CDATA[notifications]]></category>
            <dc:creator><![CDATA[Musab Dogan]]></dc:creator>
            <pubDate>Tue, 07 May 2024 15:34:08 GMT</pubDate>
            <atom:updated>2024-05-07T15:34:08.081Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Get notification in case there are less than 100 events in an hour</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TcO9g2r2KlHHIE1Hx60--w.jpeg" /></figure><p>Receiving notifications in case of interruptions or decreases in a live streaming log data is crucial for system monitoring and maintenance. While <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/how-watcher-works.html">Elasticsearch Watcher</a> offers one solution, another solution is to leverage ElastAlert. But how?</p><h3>ElastAlert — Flatline Rule</h3><p><a href="https://github.com/jertel/elastalert2">GitHub - jertel/elastalert2: ElastAlert 2 is a continuation of the original yelp/elastalert project. Pull requests are appreciated!</a></p><blockquote>The ElastAlert flatline rule is described in the official documentation as follows: “This rule matches when the total number of events is <strong>under</strong> a given threshold for a time period.” [<a href="https://elastalert2.readthedocs.io/en/latest/ruletypes.html#flatline">source</a>]</blockquote><p>Indeed, this statement holds true, but… Sometimes, executing this can be challenging due to the multitude of details that need to be understood. In this article, I will explain those details to utilize ElastAlert, especially for stream datasets like log data.</p><h4>Good to know:</h4><ul><li>Use ElastAlert 2 if you are using Elasticsearch v7 and onwards. Because of the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html">mapping type removal</a> and ElastAlert is no longer maintained.</li><li><strong>!!! You must have some kind of timestamp for ElastAlert to work. [</strong><a href="https://elastalert2.readthedocs.io/en/latest/recipes/faq.html#i-m-not-using-timestamp-what-do-i-do"><strong>source</strong></a><strong>]</strong></li><li>By default, ElastAlert uses the <strong>@timestamp</strong> field to check for matches. If this field is not exist in the index mapping, ElastAlert will throw an error. The <strong>@timestamp</strong> field is date_optional_time by default which means: <strong>yyyy-MM-dd’T’HH:mm:ss</strong> or <strong>yyyy-MM-dd’T’HH:mm:ss.SSSZ</strong> or <strong>yyyy-MM-dd</strong>. As examples, <strong>2024–04–09T00:14:47.731695047Z</strong> or <strong>2024–04–09T00:14:47</strong> or <strong>2024–04–09</strong>.</li><li>If the original @timestamp is delayed by nature and you use it within rules, ElastAlert may raise an “data outage” alarm because the data is not actually within the relevant time range according to the original @timestamp. ElastAlert suggests using buffer_time for this, but in reality, it’s not very practical because buffer_time also affects other areas.</li><li>When using the ElastAlert-Flatline rule, before sending notifications, the rule must have <strong>at least one hit</strong> document in the index. The official documentation states it like the following.</li></ul><blockquote>“When using type: flatline, ElastAlert 2 must see at least one document before it will alert you that it has stopped seeing them.” [<a href="https://elastalert2.readthedocs.io/en/latest/recipes/faq.html#i-m-using-flatline-but-i-don-t-see-any-alerts">source</a>]</blockquote><h4>Let’s get started! First, I’ll outline the steps.</h4><ol><li>Create an ingest pipeline to generate <a href="https://www.elastic.co/blog/calculating-ingest-lag-and-storing-ingest-time-in-elasticsearch-to-improve-observability">ingest_timestamp</a>.</li><li>Set the the ingest pipeline as <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html#set-default-pipeline">default_pipeline</a> or <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html#set-final-pipeline">final_pipeline</a> to the index settings (don’t forget to add it to the index template later for new indices).</li><li>Clone the ElastAlert 2 repo from GitHub</li><li>Edit the config/elastalert.yaml configuration file.</li><li>Create the rules/test-flatline.yaml configuration file.</li><li>Run ElastAlert with docker.</li></ol><h3>Let’s start!</h3><pre>#1. Create an ingest pipeline to generate ingest_timestamp.<br><br>PUT _ingest/pipeline/add_ingest_timestamp<br>{<br>  &quot;description&quot;: &quot;Add Ingest Timestamp to Documents&quot;,<br>  &quot;processors&quot;: [<br>    {<br>      &quot;set&quot;: {<br>        &quot;field&quot;: &quot;ingest_timestamp&quot;,<br>        &quot;value&quot;: &quot;{{_ingest.timestamp}}&quot;<br>      }<br>    }<br>  ]<br>}</pre><pre>#2. Set the the ingest pipeline as default_pipeline<br><br>PUT test-index<br>{<br>  &quot;settings&quot;: {<br>    &quot;index.default_pipeline&quot;: &quot;add_ingest_timestamp&quot;<br>  }<br>}</pre><pre>#3. Clone the ElastAlert 2 repo from GitHub<br><br>git clone https://github.com/jertel/elastalert2.git</pre><pre>#4. Edit the config/elastalert.yaml configuration file.<br><br>#I&#39;m using Elastic cloud. If your elasticsearch working in local use localhost for es_host. use_ssl for http or https communication.<br>es_host: &quot;musab-elastic.es.us-east-2.aws.elastic-cloud.com&quot;<br>es_port: 9243<br>use_ssl: True<br># Option basic-auth username and password for elasticsearch<br>es_username: my_user_name<br>es_password: my_secret_password<br><br># This is the folder that contains the rule yaml files<br># Any .yaml file will be loaded as a rule<br>rules_folder: rules<br><br># How often ElastAlert will query elasticsearch<br># The unit can be anything from weeks to seconds<br>run_every:<br>  minutes: 1<br><br># ElastAlert will buffer results from the most recent<br># period of time, in case some log sources are not in real time<br>buffer_time:<br>  minutes: 1<br><br>writeback_index: elastalert_status<br># If an alert fails for some reason, ElastAlert will retry<br># sending the alert until this time period has elapsed<br>alert_time_limit.days: 2</pre><pre>#5. Create the rules/test-flatline.yaml configuration file.<br><br>name: test-flatline<br>type: flatline<br>index: test-index<br>timestamp_field: ingest_timestamp<br>threshold: 10<br>use_count_query: true<br>timeframe:<br>  minutes: 3<br>#realert:<br>#  minutes: 10<br><br>filter:<br>- term:<br>    status: &quot;active&quot;<br><br>alert:<br>  - &quot;slack&quot;<br>alert_text: &quot;test elastalert&quot;<br>slack:<br>slack_webhook_url: &quot;https://hooks.slack.com/services/TLRT28UF6/B03FERU79GC&quot;</pre><pre># It&#39;s optional - if you want to test it<br><br># index a sample document<br>POST test-index/_doc<br>{<br>  &quot;test_field&quot;: &quot;value13&quot;,<br>  &quot;status&quot;: &quot;active&quot;<br>}<br><br>#The result<br>GET test-index/_search<br>  &quot;_source&quot;: {<br>    &quot;test_field&quot;: &quot;value13&quot;,<br>    &quot;ingest_timestamp&quot;: &quot;2024-04-09T01:33:12.643232465Z&quot;,<br>    &quot;status&quot;: &quot;active&quot;<br>  }</pre><pre># It&#39;s optional - if you want to test it<br><br>#testing....<br>#before run the command you sure you&#39;re in the correct directory (cd)<br>docker run --rm -it --net &quot;host&quot; \<br>    -v `pwd`/config/elastalert.yaml:/opt/elastalert/config.yaml \<br>    -v `pwd`/rules:/opt/elastalert/rules \<br>    --entrypoint elastalert-test-rule \<br>    jertel/elastalert2 \<br>    /opt/elastalert/rules/test-flatline.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cqm9Ioq9rILBwHCjpE-r0A.png" /></figure><pre>#6. Run ElastAlert with docker.<br><br>#before run the command you sure you&#39;re in the correct directory (cd)<br>docker rm elastalert -f &amp;&amp; docker run -d --net=&quot;host&quot; --name elastalert \<br>    -v `pwd`/config/elastalert.yaml:/opt/elastalert/config.yaml \<br>    -v `pwd`/rules:/opt/elastalert/rules \<br>    jertel/elastalert2:latest</pre><h3>Final Part:</h3><blockquote><strong><em>Get notification in case there are less than 100 events in an hour</em></strong></blockquote><blockquote>As mentioned before we will create a scenario for our use case. Before create the alert we should define all parameters. We want to create an alert for the following criteria.</blockquote><h4>YAML</h4><ol><li>Use Elasticsearch in Elastic Cloud es_host</li><li>use ingest_timestamp<strong> </strong>field as timestamp (ingest pipeline will create the timestamp)</li><li>Bucket: check if there are less than 100 events for each hour of buckets run_every.minutes</li><li>Timeframe check the last 120 minutes timeframe.minutes</li><li>Trigger the rule every 60 minutes</li><li>Filter and include if the terms field value is active</li><li>Get notification to slack channel with webhook.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YZ1H7mG-gMhYARQ8AJ8yWA.png" /><figcaption>The proof of concept with Elasticsearch <strong>histogram_aggregation</strong> and <strong>elastalert</strong> output.</figcaption></figure><p>You will get the notification like the following to your slack channel:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B7GV4_GfnVRS-52jBu2yXg.png" /></figure><p>Note: You will get the first notification after 2 hours because the flatline rule and timeframe.minutes set to two hours.</p><h4>Resources:</h4><p><a href="https://elastalert2.readthedocs.io/en/latest/">https://elastalert.readthedocs.io/en/latest/</a> — recommended for ESv6</p><p><a href="https://elastalert2.readthedocs.io/en/latest/">https://elastalert2.readthedocs.io/en/latest/</a> — recommended for ESv7 and onwards</p><p><a href="https://elastalert2.readthedocs.io/en/latest/recipes/faq.html">https://elastalert2.readthedocs.io/en/latest/recipes/faq.html</a></p><p><a href="https://elastalert2.readthedocs.io/en/latest/ruletypes.html#flatline">https://elastalert2.readthedocs.io/en/latest/ruletypes.html#flatline</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6909c932598" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elasticsearch’s Distributed Search: Query and Fetch Phases]]></title>
            <link>https://medium.com/@musabdogan/elasticsearchs-distributed-search-query-and-fetch-phases-df869d35f4b3?source=rss-7692320510b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/df869d35f4b3</guid>
            <category><![CDATA[query]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[fetch]]></category>
            <category><![CDATA[explanation]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <dc:creator><![CDATA[Musab Dogan]]></dc:creator>
            <pubDate>Mon, 06 May 2024 15:54:41 GMT</pubDate>
            <atom:updated>2024-05-06T16:06:26.614Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*e2eV9JGbLA7FThAX" /></figure><p>To understand Elasticsearch’s distributed search, let’s take a moment to understand how <strong>querying</strong> and <strong>fetching</strong> work. Unlike simple CRUD tasks, distributed search is like navigating through a maze of shards spread across the cluster.</p><p>In Elasticsearch, CRUD operations handle individual documents identified by their unique <strong>index</strong>, <strong>type</strong>, and routing-value (usually the document’s <strong>_id</strong>). However, search queries are more complex. They don’t have a fixed destination and must search through every shard in the index or indices to locate potential matches.</p><p>However, discovering matching documents marks just the beginning. The search API needs to combine results from various shards into a unified, organized list before displaying them to the user. This initiates the two-step process of querying and fetching.</p><p>By default, Elasticsearch utilizes a search method known as “<a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html#search-type">Query Then Fetch.</a>” This approach progresses through the following steps:</p><ol><li>Client sent a query to Elasticsearch</li><li>Broadcast the query to each shard</li><li>Find all matching documents and calculate scores using local Term/Document Frequencies</li><li>Build a priority queue of results (sort, pagination with from/to, etc)</li><li>Return metadata about the results to requesting node. Note, the actual document is not sent yet, just the scores</li><li>Scores from all the shards are merged and sorted on the requesting node, docs are selected according to query criteria</li><li>Finally, the actual docs are retrieved from individual shards where they reside.</li><li>Results are returned to the client</li></ol><p>Note: Coordinator node responsible for the steps<strong> 1,2, and 8.</strong></p><p><strong>Query Phase (3,4,5,6):</strong> the search query is sent to every shard, initiating local execution and the creation of a priority queue containing matching documents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jjsV-Z1D18YcIJVjGirHmw.png" /></figure><p><strong>Fetch Phase (7): </strong>while the query phase identifies relevant documents, the fetch phase is responsible for fetching the actual documents from their respective shards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tIXyg70eb5UXTWeGhyQijg.png" /></figure><p>This divided method guarantees effective and scalable search operations in a distributed setting. In the query phase, the search query navigates through each shard copy (<strong>primary or replica shards</strong>) to initiate local searches and compile a prioritized list of matching documents. This phase marks the initial step in refining the search results.</p><p>The fetch phase, resulting in the delivery of desired search outcomes. This phase acts as a bridge between query execution and result retrieval, ensuring the thoroughness of the search process.</p><h4>Additional information:</h4><p>Enabling Elasticsearch’s slow logs separately for query and fetch phases enables precise monitoring and optimization of search performance. Administrators can pinpoint potential bottlenecks and adjust system parameters by establishing thresholds for query and fetch durations separately.</p><p>For instance, configuring slow logs with specific thresholds for query and fetch phases can be done as follows:</p><pre>PUT *,-.*/_settings<br>{<br>  &quot;index.search.slowlog.threshold.query.warn&quot;: &quot;1s&quot;,<br>  &quot;index.search.slowlog.threshold.fetch.warn&quot;: &quot;100ms&quot;<br>}<br><br>#or with curl<br><br>curl -XPUT &quot;http://localhost:9200/*,-.*/_settings&quot; -H &quot;Content-Type: application/json&quot; -d&#39;<br>{<br>  &quot;index.search.slowlog.threshold.query.warn&quot;: &quot;1s&quot;,<br>  &quot;index.search.slowlog.threshold.fetch.warn&quot;: &quot;100ms&quot;<br>}&#39;</pre><h4>Elasticsearch query vs fetch times</h4><p>It’s expected to see way more less fetch time compared to query time. Here is <a href="https://discuss.elastic.co/t/query-vs-fetch-times/13710/2">a topic</a> that created in elastic discuss about the speed.</p><h4>Resources:</h4><ul><li><a href="https://allen8807.gitbooks.io/elasticsearch-definitive-guide-en/content/">Elasticsearch: The Definitive Guide</a></li><li><a href="https://www.elastic.co/blog/understanding-query-then-fetch-vs-dfs-query-then-fetch">Understanding Query Then Fetch vs DFS Query Then Fetch</a></li><li><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-slowlog.html">Elasticsearch Reference Documentation: Slow Logs</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df869d35f4b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elasticsearch snapshot to Google Cloud Storage (GCP) with best practices]]></title>
            <link>https://medium.com/@musabdogan/elasticsearch-snapshot-to-google-cloud-storage-gcp-with-best-practices-c17056ec59f4?source=rss-7692320510b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/c17056ec59f4</guid>
            <category><![CDATA[snapshot]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[repositories]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <dc:creator><![CDATA[Musab Dogan]]></dc:creator>
            <pubDate>Fri, 23 Feb 2024 15:10:12 GMT</pubDate>
            <atom:updated>2024-02-23T15:10:12.958Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JbHcRcWJ_ldHwJzUpPuCcQ.png" /></figure><p>In this article, we will learn how to create a repository on Google Cloud Platform (GCP). As always, there is a good elastic documentation about it but some steps are confusing who has no experience with GCP before. I will try to explain step by step with pictures.</p><p><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/repository-gcs.html">Google Cloud Storage repository | Elasticsearch Guide [8.12] | Elastic</a></p><pre>Steps: <br>1. Login Google Cloud - register and start free trial if needed<br>2. Create a bucket<br>3. Create a service account - don&#39;t forget to grant permission <br>4. Create a key<br>5. Add the key to elasitcsearch-keystore</pre><h3>1. Login Google Cloud — register and start free trial if needed</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZcB8mngf9JbMPSrXcZo_Ug.png" /></figure><p>GCP accounts consist of projects. Create one and start. <a href="https://console.cloud.google.com/">https://console.cloud.google.com/</a></p><h3>2. Create a bucket</h3><p><a href="https://console.cloud.google.com/storage/browser">https://console.cloud.google.com/storage/browser</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1svMVMI3c8qMUIa6TQwt9Q.png" /></figure><p>The bucket will keep the snapshots. We will use this bucket name during repository creation. In general, it’s called dev, stg, or prod. In addition, if you have multiple clusters it’d make sense to have seperated bucket for each cluster. Here is recommended bucket name for prod env `{your_cluster_name}_repo`.</p><pre>To decrease data transfer costs for snapshot,<br>It&#39;s recommended to choose the bucket and elasticsearch cluster region the same.</pre><h3>3. Create a service account — don’t forget to grant permission</h3><p><a href="https://console.cloud.google.com/iam-admin/serviceaccounts">https://console.cloud.google.com/iam-admin/serviceaccounts</a></p><p>IAM permission will grant access to service account. You can enable/disable add/remove anytime you want. The service account name that we created is <strong>my_user</strong>. We will grant <strong>storage object admin </strong>role the <strong>my_user</strong>.</p><h4>3.1 Create Service Account — create user</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tIN4TKCbNQLClGV_IzdqLA.png" /></figure><h4>3.2 Create Service Account — create user</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d3gOSGyn9fyRjou2SltfuA.png" /></figure><h4>3.3 Create Service Account — grant access</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFkxHwbxEM4v31wkInNttA.png" /></figure><h4>3.4 (optional) Create Service Account — check the permission</h4><p>It should look like the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vdqIuPdigOfu5bN7nBmFgg.png" /></figure><h3>4. Create a key</h3><p>Create a key for <strong>my_user, </strong>currently on ESv8 only JSON is supported.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6kxqt1MBG2vGBBlhIDqaZQ.png" /></figure><p>Here is my example, please don’t copy/paste create your own.</p><pre>#cat nth-condition-415209–309899125ad4.json<br>{<br> &quot;type&quot;: &quot;service_account&quot;,<br> &quot;project_id&quot;: &quot;nth-passage-415209&quot;,<br> &quot;private_key_id&quot;: &quot;309899125ad4b2bf2b851cbda357cc8d54538350&quot;,<br> &quot;private_key&quot;: &quot; - - -BEGIN PRIVATE KEY - - -\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCpjn5Tf9HSEALk - - -END PRIVATE KEY - - -\n&quot;,<br> &quot;client_email&quot;: &quot;test-service-account@nth-passage-415209.iam.gserviceaccount.com&quot;,<br> &quot;client_id&quot;: &quot;116189663697024011135&quot;,<br> &quot;auth_uri&quot;: &quot;https://accounts.google.com/o/oauth2/auth&quot;,<br> &quot;token_uri&quot;: &quot;https://oauth2.googleapis.com/token&quot;,<br> &quot;auth_provider_x509_cert_url&quot;: &quot;https://www.googleapis.com/oauth2/v1/certs&quot;,<br> &quot;client_x509_cert_url&quot;: &quot;https://www.googleapis.com/robot/v1/metadata/x509/test-service-account%40nth-passage-415209.iam.gserviceaccount.com&quot;,<br> &quot;universe_domain&quot;: &quot;googleapis.com&quot;<br>}</pre><h3>5. Add the key to elasticsearch-keystore</h3><p>For elastic cloud you can add the key to elasticsearch keystore like in the following image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BRDwr3OXi-XOhtkp6kQ98Q.png" /></figure><p>For self-managed elastic cloud you can add the key to elasticsearch-keystore like the following</p><pre>bin/elasticsearch-keystore add-file gcs.client.default.credentials_file /path/to/nth-condition-415209–309899125ad4.json</pre><blockquote>Well done, gcp bucket key added to elasticsearch-keystore!</blockquote><p>Now it’s time to create a repo and verify it. You can use the following commands on Kibana DevTools also you can create/manage repository on snapshot&amp;restore section of Kibana.</p><h4>create the repository</h4><pre>PUT _snapshot/my_gcs_repository<br>{<br> &quot;type&quot;: &quot;gcs&quot;,<br> &quot;settings&quot;: {<br> &quot;bucket&quot;: &quot;my_repo&quot;,<br> &quot;client&quot;: &quot;my_client&quot;<br> }<br>}</pre><h4>verify the repo</h4><pre>POST _snapshot/my_gcs_repository/_verify</pre><h4>Create a snapshot</h4><pre>PUT _snapshot/my_gcs_repository/all_cluster_snapshot<br>{<br> &quot;indices&quot;: &quot;*&quot;,<br> &quot;ignore_unavailable&quot;: false,<br> &quot;include_global_state&quot;: true<br>}</pre><h4>Check the status of snapshot</h4><pre>GET _snapshot/my_gcs_repository/migration/_status</pre><h4>Here is how a Google Cloud Bucket looks like when you create a snapshot.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2oYbZ1kh0R1l28DmqKYYw.png" /></figure><h4>References:</h4><pre>https://www.youtube.com/live/LD2jGABeUMc?si=XJ0HsINpAKUS1QrR<br>https://www.elastic.co/guide/en/elasticsearch/reference/current/repository-gcs.html<br>https://medium.com/@chandrapal/backup-and-restore-elasticsearch-data-using-gcs-b047f3c680d9</pre><h4>Here are some permission errors that you can face with. If you experience any of them, check “Create a service account — don’t forget to grant permission” section</h4><pre>{<br>  &quot;error&quot;: {<br>    &quot;root_cause&quot;: [<br>      {<br>        &quot;type&quot;: &quot;repository_exception&quot;,<br>        &quot;reason&quot;: &quot;[my_gcs_repository] Could not determine repository generation from root blobs&quot;<br>      }<br>    ],<br>    &quot;type&quot;: &quot;repository_exception&quot;,<br>    &quot;reason&quot;: &quot;[my_gcs_repository] Could not determine repository generation from root blobs&quot;,<br>    &quot;caused_by&quot;: {<br>      &quot;type&quot;: &quot;storage_exception&quot;,<br>      &quot;reason&quot;: &quot;@.iam.gserviceaccount.com does not have storage.objects.list access to the Google Cloud Storage bucket. Permission &#39;storage.objects.list&#39; denied on resource (or it may not exist).&quot;,<br>      &quot;caused_by&quot;: {<br>        &quot;type&quot;: &quot;google_json_response_exception&quot;,<br>        &quot;reason&quot;: &quot;&quot;&quot;403 Forbidden<br>GET https://storage.googleapis.com/storage/v1/b//o?delimiter=/&amp;prefix=index-&amp;projection=full<br>{<br>  &quot;code&quot; : 403,<br>  &quot;errors&quot; : [ {<br>    &quot;domain&quot; : &quot;global&quot;,<br>    &quot;message&quot; : &quot;@.iam.gserviceaccount.com does not have storage.objects.list access to the Google Cloud Storage bucket. Permission &#39;storage.objects.list&#39; denied on resource (or it may not exist).&quot;,<br>    &quot;reason&quot; : &quot;forbidden&quot;<br>  } ],<br>  &quot;message&quot; : &quot;@.iam.gserviceaccount.com does not have storage.objects.list access to the Google Cloud Storage bucket. Permission &#39;storage.objects.list&#39; denied on resource (or it may not exist).&quot;<br>}&quot;&quot;&quot;<br>      }<br>    }<br>  },<br>  &quot;status&quot;: 500<br>}<br><br><br>#error2<br><br>{<br>  &quot;error&quot;: {<br>    &quot;root_cause&quot;: [<br>      {<br>        &quot;type&quot;: &quot;repository_verification_exception&quot;,<br>        &quot;reason&quot;: &quot;[musab-gcp-repo] path  is not accessible on master node&quot;<br>      }<br>    ],<br>    &quot;type&quot;: &quot;repository_verification_exception&quot;,<br>    &quot;reason&quot;: &quot;[musab-gcp-repo] path  is not accessible on master node&quot;,<br>    &quot;caused_by&quot;: {<br>      &quot;type&quot;: &quot;storage_exception&quot;,<br>      &quot;reason&quot;: &quot;&quot;&quot;403 Forbidden<br>POST https://storage.googleapis.com/upload/storage/v1/b/musab_elasticsearch_snapshot/o?ifGenerationMatch=0&amp;projection=full&amp;uploadType=multipart<br>{<br>  &quot;error&quot;: {<br>    &quot;code&quot;: 403,<br>    &quot;message&quot;: &quot;@.iam.gserviceaccount.com does not have storage.objects.create access to the Google Cloud Storage object. Permission &#39;storage.objects.create&#39; denied on resource (or it may not exist).&quot;,<br>    &quot;errors&quot;: [<br>      {<br>        &quot;message&quot;: &quot;@.iam.gserviceaccount.com does not have storage.objects.create access to the Google Cloud Storage object. Permission &#39;storage.objects.create&#39; denied on resource (or it may not exist).&quot;,<br>        &quot;domain&quot;: &quot;global&quot;,<br>        &quot;reason&quot;: &quot;forbidden&quot;<br>      }<br>    ]<br>  }<br>}<br>&quot;&quot;&quot;<br>    }<br>  },<br>  &quot;status&quot;: 500<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c17056ec59f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Does Elasticsearch Handle Uppercase vs. Lowercase Letters in the Aggs Order?]]></title>
            <link>https://medium.com/@musabdogan/how-does-elasticsearch-handle-uppercase-vs-lowercase-letters-in-the-aggs-order-4eb061d5ec42?source=rss-7692320510b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/4eb061d5ec42</guid>
            <category><![CDATA[normalizer]]></category>
            <category><![CDATA[sorting]]></category>
            <category><![CDATA[uppercase]]></category>
            <category><![CDATA[lowercase]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <dc:creator><![CDATA[Musab Dogan]]></dc:creator>
            <pubDate>Wed, 29 Nov 2023 11:20:06 GMT</pubDate>
            <atom:updated>2023-11-29T11:37:06.558Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*i0GZxAUOzuOTiqif" /></figure><h3>Overview</h3><p>Elasticsearch sorting allows you to order your search results based on specific criteria. However, when handling case sensitivity in sorting, Elasticsearch treats uppercase and lowercase letters as different characters, sorting them separately. This is because of the ASCII table order, which goes from uppercase A to lowercase z.</p><p>By default, Elasticsearch sorts strings in the following order: numbers first, then uppercase letters, and finally lowercase letters. For instance, if you have the terms “Apple,” “apple,” “banana,” “Carrot,” and “1apple,” they would be sorted in ascending order as “1apple,” “Apple,” “Carrot,” “apple,” “banana.”</p><pre>POST /test_casing/_bulk<br>{ &quot;index&quot; : {} }<br>{ &quot;my_field&quot; : &quot;Apple&quot; }<br>{ &quot;index&quot; : {} }<br>{ &quot;my_field&quot; : &quot;apple&quot; }<br>{ &quot;index&quot; : {} }<br>{ &quot;my_field&quot; : &quot;banana&quot; }<br>{ &quot;index&quot; : {} }<br>{ &quot;my_field&quot; : &quot;Carrot&quot; }<br>{ &quot;index&quot; : {} }<br>{ &quot;my_field&quot; : &quot;1apple&quot; }</pre><pre>GET /test_casing/_search<br>{<br>  &quot;size&quot;: 0,<br>  &quot;aggs&quot;: {<br>    &quot;my_terms&quot;: {<br>      &quot;terms&quot;: {<br>        &quot;field&quot;: &quot;my_field.keyword&quot;<br>      }<br>    }<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zBg2RsRJun-4jDQu" /></figure><p>This default behavior might not always be desirable. For example, if you have indexed the values “Apple,” “banana,” and “Carrot,” and you’re using ascending order, you would get “Apple,” “Carrot,” “banana.” However, you might want to get “Apple,” “banana,” “Carrot” instead.</p><p>To achieve that, you can use a feature in Elasticsearch called a <a href="https://opster.com/guides/elasticsearch/data-architecture/elasticsearch-normalizers/">normalizer</a>. A normalizer is used with the keyword field type and allows you to preprocess the input of keyword fields in a way that’s similar to analyzing text.</p><p>However, unlike analyzers, a normalizer does not break the input into tokens. This makes it suitable for keyword field types where the entire input needs to be indexed or sorted.</p><pre>PUT /test_casing2<br>{<br>  &quot;settings&quot;: {<br>    &quot;analysis&quot;: {<br>      &quot;normalizer&quot;: {<br>        &quot;my_normalizer&quot;: {<br>          &quot;type&quot;: &quot;custom&quot;,<br>          &quot;filter&quot;: [<br>            &quot;lowercase&quot;<br>          ]<br>        }<br>      }<br>    }<br>  },<br>  &quot;mappings&quot;: {<br>    &quot;properties&quot;: {<br>      &quot;my_field&quot;: {<br>        &quot;type&quot;: &quot;keyword&quot;,<br>        &quot;normalizer&quot;: &quot;my_normalizer&quot;<br>      }<br>    }<br>  }<br>}</pre><pre>POST /test_casing2/_bulk<br>{&quot;index&quot;:{}}<br>{&quot;my_field&quot;:&quot;Apple&quot;}<br>{&quot;index&quot;:{}}<br>{&quot;my_field&quot;:&quot;banana&quot;}<br>{&quot;index&quot;:{}}<br>{&quot;my_field&quot;:&quot;Carrot&quot;}</pre><pre>GET /test_casing2/_search<br>{<br>  &quot;size&quot;: 0,<br>  &quot;aggs&quot;: {<br>    &quot;my_terms&quot;: {<br>      &quot;terms&quot;: {<br>        &quot;field&quot;: &quot;my_field&quot;<br>      }<br>    }<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E4fE6hldbLdc8SCk" /></figure><p><strong>It’s important to note that using a normalizer will change the values in your index.</strong> If you want to keep the original values, such as “Apple” with a capital “A,” you can use sub-fields. That allows you to keep both the original and normalized field values. <strong>In the aggregation results, Elasticsearch will only show the field that you used in the aggregation.</strong></p><p>Unfortunately, Elasticsearch does not support case-insensitive sorting directly in the terms aggregation. Even with the use of script aggregations and normalizers, <strong>it’s not possible to sort in a case-insensitive manner and display the result with case sensitivity.</strong> This is a limitation that users should be aware of when working with Elasticsearch.</p><h3>How can you add a normalizer to an existing index?</h3><p>Let’s look at a practical example of the process of adding a normalizer to an existing index in Elasticsearch. This process involves several steps: closing the index, updating the settings, reopening the index, updating the mapping, updating the data index, and finally, running a query.</p><p>First, you need to close the index using the following command:</p><pre>POST test_casing/_close</pre><p>Next, you update the settings of the index to add the normalizer. In this case, we’re adding a custom normalizer that applies a lowercase filter:</p><pre>PUT test_casing/_settings<br>{<br>  &quot;analysis&quot;: {<br>    &quot;normalizer&quot;: {<br>      &quot;my_normalizer&quot;: {<br>        &quot;type&quot;: &quot;custom&quot;,<br>        &quot;filter&quot;: [<br>          &quot;lowercase&quot;<br>        ]<br>      }<br>    }<br>  }<br>}</pre><p>After updating the settings, you can reopen the index:</p><pre>POST test_casing/_open</pre><p>Now, you need to update the mapping of the index to use the normalizer. Here, we’re adding a sub-field to “my_field” that uses the normalizer:</p><pre>PUT test_casing/_mapping<br>{<br>  &quot;properties&quot;: {<br>    &quot;my_field&quot;: {<br>      &quot;type&quot;: &quot;text&quot;,<br>      &quot;fields&quot;: {<br>        &quot;normalized&quot;: {<br>          &quot;type&quot;: &quot;keyword&quot;,<br>          &quot;normalizer&quot;: &quot;my_normalizer&quot;<br>        }<br>      }<br>    }<br>  }<br>}</pre><p>Note that <strong>my_field.normalized </strong>is the field name.</p><p>Next, you can update the data index by running update_by_query, which will add data inside of the my_field.normalized field:</p><pre>POST test_casing/_update_by_query</pre><p>Finally, you can run a search query on the index. In this case, we’re running an aggregation on the new normalized field:</p><pre>GET /test_casing/_search<br>{<br>  &quot;size&quot;: 0,<br>  &quot;aggs&quot;: {<br>    &quot;my_terms&quot;: {<br>      &quot;terms&quot;: {<br>        &quot;field&quot;: &quot;my_field.normalized&quot;<br>      }<br>    }<br>  }<br>}</pre><p>This process demonstrates how you can add a normalizer to an existing index in Elasticsearch, allowing you to handle case sensitivity with greater flexibility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XudyeWGJ00VtZPLi" /></figure><h3>Conclusion</h3><p>In conclusion, while Elasticsearch provides powerful features for handling and manipulating data, it’s important to understand its limitations and how to work around them. Using features like normalizers and sub-fields can help you achieve the desired results.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4eb061d5ec42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Impact of the ignore_above parameter on disk usage in Elasticsearch]]></title>
            <link>https://medium.com/@musabdogan/understanding-the-impact-of-the-ignore-above-parameter-on-disk-usage-in-elasticsearch-06da297992b5?source=rss-7692320510b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/06da297992b5</guid>
            <category><![CDATA[field]]></category>
            <category><![CDATA[disk-usage]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[ignore]]></category>
            <dc:creator><![CDATA[Musab Dogan]]></dc:creator>
            <pubDate>Sun, 22 Oct 2023 14:40:31 GMT</pubDate>
            <atom:updated>2023-10-22T14:40:31.901Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DXFUjczsyg4iuzsSxTLINw.png" /></figure><p>In Elasticsearch, the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/ignore-above.html">ignore_above</a> parameter allows you to ignore (not index) strings longer than a specified length. This can be useful for limiting the size of fields to avoid performance issues. In this article, we will explore how the `ignore_above` parameter impacts the size of fields in Elasticsearch and we will compare the disk usage between two different ignore_above parameter.</p><p>First, we create an index named `test_index` with three fields: `field_ignore_above_4`, `field_ignore_above_256`, and `field_ignore_above_512`. Each field is of type `keyword` and has a different `ignore_above` setting:</p><pre>PUT test_index<br>{<br>  &quot;mappings&quot;: {<br>    &quot;properties&quot;: {<br>       &quot;field_ignore_above_4&quot;: {<br>        &quot;type&quot;: &quot;keyword&quot;,<br>        &quot;ignore_above&quot;: 4<br>      },<br>      &quot;field_ignore_above_256&quot;: {<br>        &quot;type&quot;: &quot;keyword&quot;,<br>        &quot;ignore_above&quot;: 256<br>      },<br>      &quot;field_ignore_above_512&quot;: {<br>        &quot;type&quot;: &quot;keyword&quot;,<br>        &quot;ignore_above&quot;: 512<br>      }<br>    }<br>  }<br>}</pre><p>Next, we insert a document into `test_index`:</p><pre>PUT test_index/_doc/1<br>{<br>  &quot;field_ignore_above_4&quot;: &quot;some value&quot;,<br>  &quot;field_ignore_above_256&quot;: &quot;some value&quot;,<br>  &quot;field_ignore_above_512&quot;: &quot;some value&quot;<br>}</pre><p>When we perform a search on `test_index`, we can see that the `<strong>field_ignore_above_4</strong>` is ignored because its value exceeds the `ignore_above` limit:</p><pre>GET test_index/_search</pre><p>The response shows that `field_ignore_above_4` is ignored:</p><pre>{<br>  &quot;took&quot;: 0,<br>  &quot;timed_out&quot;: false,<br>  &quot;_shards&quot;: {<br>    &quot;total&quot;: 1,<br>    &quot;successful&quot;: 1,<br>    &quot;skipped&quot;: 0,<br>    &quot;failed&quot;: 0<br>  },<br>  &quot;hits&quot;: {<br>    &quot;total&quot;: {<br>      &quot;value&quot;: 1,<br>      &quot;relation&quot;: &quot;eq&quot;<br>    },<br>    &quot;max_score&quot;: 1,<br>    &quot;hits&quot;: [<br>      {<br>        &quot;_index&quot;: &quot;test_index&quot;,<br>        &quot;_id&quot;: &quot;1&quot;,<br>        &quot;_score&quot;: 1,<br>        &quot;_ignored&quot;: [<br>          &quot;field_ignore_above_4&quot;<br>        ],<br>        &quot;_source&quot;: {<br>          &quot;field_ignore_above_4&quot;: &quot;some value&quot;,<br>          &quot;field_ignore_above_256&quot;: &quot;some value&quot;,<br>          &quot;field_ignore_above_512&quot;: &quot;some value&quot;<br>        }<br>      }<br>    ]<br>  }<br>}</pre><p>Now, we can calculate the size of the fields using the `_disk_usage` API:</p><pre>POST /test_index/_disk_usage?run_expensive_tasks=true&amp;filter_path=**.fields.field*</pre><p>The response provides detailed information about the size of each field:</p><pre>{<br>  &quot;test_index&quot;: {<br>    &quot;fields&quot;: {<br>      &quot;field_ignore_above_256&quot;: {<br>        &quot;total&quot;: &quot;30b&quot;,<br>        &quot;total_in_bytes&quot;: 30,<br>        &quot;inverted_index&quot;: {<br>          &quot;total&quot;: &quot;19b&quot;,<br>          &quot;total_in_bytes&quot;: 19<br>        },<br>        &quot;stored_fields&quot;: &quot;0b&quot;,<br>        &quot;stored_fields_in_bytes&quot;: 0,<br>        &quot;doc_values&quot;: &quot;11b&quot;,<br>        &quot;doc_values_in_bytes&quot;: 11,<br>        &quot;points&quot;: &quot;0b&quot;,<br>        &quot;points_in_bytes&quot;: 0,<br>        &quot;norms&quot;: &quot;0b&quot;,<br>        &quot;norms_in_bytes&quot;: 0,<br>        &quot;term_vectors&quot;: &quot;0b&quot;,<br>        &quot;term_vectors_in_bytes&quot;: 0,<br>        &quot;knn_vectors&quot;: &quot;0b&quot;,<br>        &quot;knn_vectors_in_bytes&quot;: 0<br>      },<br>      &quot;field_ignore_above_512&quot;: {<br>        &quot;total&quot;: &quot;30b&quot;,<br>        &quot;total_in_bytes&quot;: 30,<br>        &quot;inverted_index&quot;: {<br>          &quot;total&quot;: &quot;19b&quot;,<br>          &quot;total_in_bytes&quot;: 19<br>        },<br>        &quot;stored_fields&quot;: &quot;0b&quot;,<br>        &quot;stored_fields_in_bytes&quot;: 0,<br>        &quot;doc_values&quot;: &quot;11b&quot;,<br>        &quot;doc_values_in_bytes&quot;: 11,<br>        &quot;points&quot;: &quot;0b&quot;,<br>        &quot;points_in_bytes&quot;: 0,<br>        &quot;norms&quot;: &quot;0b&quot;,<br>        &quot;norms_in_bytes&quot;: 0,<br>        &quot;term_vectors&quot;: &quot;0b&quot;,<br>        &quot;term_vectors_in_bytes&quot;: 0,<br>        &quot;knn_vectors&quot;: &quot;0b&quot;,<br>        &quot;knn_vectors_in_bytes&quot;: 0<br>      }<br>    }<br>  }<br>}</pre><blockquote><strong>From the response, we can see that both </strong>field_ignore_above_256<strong> and field_ignore_above_512 have the same total size of 30 bytes.</strong></blockquote><p>Interestingly, `field_ignore_above_4` is not included in the disk usage statistics because it was ignored during indexing due to the `ignore_above` setting. This demonstrates how the `ignore_above` parameter can be used to control the size of your fields and optimize your Elasticsearch storage usage.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06da297992b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Elasticsearch’s Auto-Generated _id: Is Duplication a Concern?]]></title>
            <link>https://medium.com/@musabdogan/understanding-elasticsearchs-auto-generated-id-is-duplication-a-concern-3ced51e14f93?source=rss-7692320510b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ced51e14f93</guid>
            <category><![CDATA[auto-generate]]></category>
            <category><![CDATA[document]]></category>
            <category><![CDATA[index]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[unique-id]]></category>
            <dc:creator><![CDATA[Musab Dogan]]></dc:creator>
            <pubDate>Mon, 16 Oct 2023 22:41:39 GMT</pubDate>
            <atom:updated>2023-10-16T22:41:39.041Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Elasticsearch’s Auto-Generated document _id: Is Duplication a Concern?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*DiOAp2pxdp5Yaeot" /></figure><h3>Auto-Generated Document IDs in Elasticsearch</h3><p>When you index a document without specifying an ID, Elasticsearch automatically generates a unique ID for that document. This ID is a Base64-encoded UUID, which is composed of several parts, each serving a specific purpose.</p><p>The ID generation process is optimized for both indexing speed and storage efficiency. The code responsible for this process can be found in Elasticsearch’s TimeBasedUUIDGenerator class on GitHub.</p><p><a href="https://github.com/elastic/elasticsearch/blob/99f88f15c5febbca2d13b5b5fda27b844153bf1a/server/src/main/java/org/elasticsearch/common/TimeBasedUUIDGenerator.java#L80-L118">elasticsearch/server/src/main/java/org/elasticsearch/common/TimeBasedUUIDGenerator.java at 99f88f15c5febbca2d13b5b5fda27b844153bf1a · elastic/elasticsearch</a></p><h3>How are the IDs Generated?</h3><p>The first two bytes of the ID are derived from a sequence ID, which is incremented for each document that’s indexed. The first and third bytes of the sequence ID are used. These bytes change frequently, which helps with indexing speed because it makes the IDs sort quickly.</p><p>The next four bytes are derived from the current timestamp. These bytes change less frequently, which helps with storage efficiency because it makes the IDs compress well. The timestamp is shifted by different amounts to generate these four bytes, which means they change at different rates.</p><p>The next six bytes are the MAC address of the machine where Elasticsearch is running. This helps ensure the uniqueness of the IDs across different machines.</p><p>The final three bytes are the remaining bytes of the timestamp and sequence ID. These bytes are likely not to be compressed at all.</p><p>The resulting byte array is then Base64-encoded to create the final ID. The Base64 encoding is URL-safe and does not include padding, which makes the IDs safe to use in URLs and efficient to store.</p><h3>Probability of Collision</h3><p>The probability of Elasticsearch generating a duplicate ID for a document is extremely low, almost negligible. This is because Elasticsearch uses a UUID (Universally Unique Identifier) for auto-generating IDs. UUIDs are 128-bit values and are designed to be sufficiently random such that the probability of collision (i.e., generating the same UUID more than once) is extremely low.</p><h3>Example of an Auto-Generated ID</h3><p>Let’s consider an example auto-generated ID: “5PMM3nYBgTGA2v2S6qve”. This ID is a Base64-encoded UUID. The first two bytes are derived from a sequence ID, the next four bytes are derived from the current timestamp, the next six bytes are the MAC address of the machine where Elasticsearch is running, and the final three bytes are the remaining bytes of the timestamp and sequence ID.</p><h3>Q&amp;A</h3><h4>Q: Are auto-generated IDs unique across all indices in a cluster?</h4><p>A: While the auto-generated IDs are unique within an index, they are not globally unique across all indices in a cluster. If you have two documents with the same auto-generated ID in two different indices, they are considered as two different documents.</p><h4>Q: What is the probability of collision in auto-generated IDs?</h4><p>A: The probability of Elasticsearch generating a duplicate ID for a document is extremely low, almost negligible. This is because Elasticsearch uses a UUID for auto-generating IDs, which are designed to be sufficiently random such that the probability of collision is extremely low.</p><p>To give you an idea of how low: The number of random version 4 UUIDs (which are the type of UUIDs used by Elasticsearch) that need to be generated in order to have a 50% probability of at least one collision is 2.71 quintillion (2.71 x 1⁰¹⁸). This number is so large that even if you were generating 1 billion UUIDs per second, it would take you over 85 years to generate this many UUIDs.</p><h3>Conclusion</h3><p>Elasticsearch’s approach to ID generation is a trade-off between indexing speed, storage efficiency, and lookup speed. It’s optimized for append-only workloads, where documents are continually being added to the index and rarely updated or deleted.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ced51e14f93" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>