{"id":5470,"date":"2026-03-26T11:25:27","date_gmt":"2026-03-26T11:25:27","guid":{"rendered":"https:\/\/sparksupport.com\/blog\/?p=5470"},"modified":"2026-03-26T11:47:00","modified_gmt":"2026-03-26T11:47:00","slug":"fix-slow-elasticsearch-queries-spring-boot","status":"publish","type":"post","link":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/","title":{"rendered":"How to Fix Slow Elasticsearch Queries in Spring Boot (5 Seconds to Under 500ms)"},"content":{"rendered":"\n<p><em>Elasticsearch running slow on millions of records? Here\u2019s the exact query-level fix our Java engineers applied to achieve a 90% performance improvement in a live Spring Boot production system.<\/em><\/p>\n\n\n\n<p><strong>Why Elasticsearch Searches Are So Slow (And How We Fixed It)<\/strong><\/p>\n\n\n\n<p>At Sparksupport, our <a href=\"https:\/\/sparksupport.com\/java-development\"><strong>Java development team<\/strong><\/a> regularly works on high-volume enterprise systems built with Spring Boot and Elasticsearch. On one such production project, we were dealing with over 5 million records \u2014 and search queries were consistently taking 3 to 5 seconds to respond.<\/p>\n\n\n\n<p>For any production application, that kind of latency is unacceptable. Users felt it, stakeholders flagged it, and the engineering team needed answers fast.<\/p>\n\n\n\n<p>After systematic debugging and testing, we brought the response time down to under 500 milliseconds \u2014 a <strong>90% improvement<\/strong> \u2014 without changing the infrastructure, adding hardware, or re-architecting the data model.<\/p>\n\n\n\n<p>This blog breaks down the exact mistakes we found and the specific fixes that made all the difference. If your Elasticsearch performance is suffering, the root cause is almost certainly in how the queries are written \u2014 not in the volume of data.<\/p>\n\n\n\n<div class=\"wp-block-group alignfull\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\ud83d\udca1 Quick Takeaway <br><\/strong>Elasticsearch performance problems on large datasets are almost always a query design problem, not a hardware or data volume problem. The fixes are simpler than you think.<\/p>\n<\/blockquote>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Setup: 5 Million Records, Simple Queries, Terrible Performance<\/strong><\/h2>\n\n\n\n<p>The system was straightforward. Users searched across a dataset of 5+ million event records using basic filters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>eventId<\/strong> \u2014 an exact identifier<\/li>\n\n\n\n<li><strong>status<\/strong> \u2014 a fixed enum value like ACTIVE or INACTIVE<\/li>\n\n\n\n<li><strong>timestamp<\/strong> \u2014 a date\/time field for range filtering<\/li>\n<\/ul>\n\n\n\n<p>No complex full-text search. No fuzzy matching. Just structured lookups on known fields.<\/p>\n\n\n\n<p>Despite this, every query was painfully slow. The problem wasn\u2019t the data \u2014 it was how Elasticsearch was being asked to process it. Three anti-patterns were compounding on each other to produce terrible performance at scale.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Elasticsearch Anti-Patterns That Kill Performance at Scale<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Anti-Pattern 1: Using match for Exact-Value Fields<\/strong><\/h3>\n\n\n\n<p>The team was using <strong>match<\/strong> queries for fields like <strong>eventId<\/strong> \u2014 a natural-looking choice, but the wrong one for this use case:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{<br>  \"query\": {<br>    \"match\": {<br>      \"eventId\": \"12345\"<br>    }<br>  }<br>}<\/pre>\n\n\n\n<p>The <strong>match<\/strong> query is designed for <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/full-text-queries.html\">full-text search<\/a>. It runs the input through a text analyser before searching \u2014 tokenising it, lowercasing it, and applying filters. For a field like <strong>eventId<\/strong>, which is a plain identifier, that entire analysis pipeline runs unnecessarily on every single query.<\/p>\n\n\n\n<p>At 5 million records, even this small overhead multiplies into seconds of wasted processing time.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u274c The Problem<\/strong> match triggers text analysis on every query \u2014 completely unnecessary for IDs, status fields, or enums. It adds overhead and can return unexpected results.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Anti-Pattern 2: Using must When Scoring Isn\u2019t Needed<\/strong><\/h3>\n\n\n\n<p>Boolean <strong>must<\/strong> was the default choice for all filter conditions:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{<br>  \"query\": {<br>    \"bool\": {<br>      \"must\": [<br>        { \"term\": { \"status\": \"ACTIVE\" } }<br>      ]<br>    }<br>  }<br>}<\/pre>\n\n\n\n<p>The <strong>must<\/strong> clause does two things: it filters results AND calculates a <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-filter-context.html\">relevance score<\/a> for every matching document. When your only goal is to retrieve records where <strong>status = ACTIVE<\/strong>, relevance scoring is completely pointless \u2014 but Elasticsearch still calculates it for every single document in the result set.<\/p>\n\n\n\n<p>On millions of records, this adds up fast. The scoring overhead was silently inflating every query\u2019s execution time.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u274c The Problem<\/strong> must calculates relevance scores even when you don&#8217;t need them. On large datasets, this is pure wasted computation.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Anti-Pattern 3: Deep Pagination with from and size<\/strong><\/h3>\n\n\n\n<p>Standard pagination was implemented using <strong>from<\/strong> and <strong>size<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{<br>  \"from\": 10000,<br>  \"size\": 10<br>}<\/pre>\n\n\n\n<p>This is one of the most dangerous Elasticsearch patterns on large datasets. To return page 1001 with 10 results per page, Elasticsearch doesn\u2019t just fetch 10 records \u2014 it fetches and sorts all 10,010 records across all shards, then discards the first 10,000.<\/p>\n\n\n\n<p>As page numbers climb, so does the work. By page 500, Elasticsearch is scanning and sorting 5 million records just to return 10. This is known as the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/paginate-search-results.html\">deep pagination problem<\/a>, and it\u2019s a well-documented Elasticsearch performance killer.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u274c The Problem<\/strong> from + size forces Elasticsearch to fetch and sort every skipped record. At deep pages and high volumes, this becomes catastrophically slow.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Fixes That Brought Elasticsearch from 5s Down to Under 500ms<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Fix 1: Switch from match to term with .keyword<\/strong><\/h3>\n\n\n\n<p>For all exact-value fields \u2014 IDs, status codes, enums \u2014 we replaced <strong>match<\/strong> with <strong>term<\/strong> queries on the <strong>.keyword<\/strong> sub-field:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{<br>  \"query\": {<br>    \"term\": {<br>      \"eventId.keyword\": \"12345\"<br>    }<br>  }<br>}<\/pre>\n\n\n\n<p>The <strong>term<\/strong> query skips the analysis pipeline entirely and performs a direct lookup in Elasticsearch\u2019s inverted index. It\u2019s fast, precise, and exactly right for any field where you need an exact match. The <strong>.keyword<\/strong> sub-field ensures the value is matched as stored, with no tokenisation applied.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u2705 The Fix<\/strong> Use term queries for IDs, enums, and status fields. Always target the .keyword sub-field for string exact matches. This alone eliminated seconds from query time.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Fix 2: Replace must with filter<\/strong><\/h3>\n\n\n\n<p>Everywhere we were filtering (not ranking), we switched from <strong>must<\/strong> to <strong>filter<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{<br>  \"query\": {<br>    \"bool\": {<br>      \"filter\": [<br>        { \"term\": { \"status\": \"ACTIVE\" } }<br>      ]<br>    }<br>  }<br>}<\/pre>\n\n\n\n<p>The <strong>filter<\/strong> clause does one thing: it checks whether a document matches the condition. It does not calculate any relevance score. That\u2019s a significant reduction in work per document.<\/p>\n\n\n\n<p>Even better, Elasticsearch can <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-filter-context.html\">cache filter results<\/a> at the segment level. When the same filter runs multiple times (e.g., <strong>status = ACTIVE<\/strong> is a very common query), the cached result is reused, making repeated queries near-instant.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u2705 The Fix<\/strong> Always use filter instead of must when relevance ranking is not required. It skips scoring, enables caching, and dramatically reduces query overhead.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Fix 3: Replace Deep Pagination with search_after<\/strong><\/h3>\n\n\n\n<p>We replaced the <strong>from \/ size<\/strong> pagination pattern with Elasticsearch\u2019s <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/paginate-search-results.html#search-after\">search_after<\/a> API:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{<br>  \"size\": 10,<br>  \"search_after\": [12345],<br>  \"sort\": [<br>    { \"eventId\": \"asc\" }<br>  ]<br>}<\/pre>\n\n\n\n<p>Instead of skipping records by offset, <strong>search_after<\/strong> continues from the last document\u2019s sort value. Elasticsearch doesn\u2019t have to scan or discard any records \u2014 it jumps directly to the correct position in the index.<\/p>\n\n\n\n<p>The performance difference at scale is dramatic. Whether you\u2019re on page 2 or page 2,000, the query cost remains constant. This is the recommended approach for any paginated access across large datasets.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u2705 The Fix<\/strong> Use search_after for paginating large datasets. It maintains constant query cost regardless of how deep into the dataset you go.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Fix 4: Define Correct Field Mappings Upfront<\/strong><\/h2>\n\n\n\n<p>One of the most impactful (and most overlooked) performance factors is <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/mapping.html\">index mapping<\/a>. We explicitly mapped <strong>eventId<\/strong> as a <strong>keyword<\/strong> type instead of relying on Elasticsearch\u2019s dynamic mapping:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{<br>  \"mappings\": {<br>    \"properties\": {<br>      \"eventId\": { \"type\": \"keyword\" },<br>      \"description\": { \"type\": \"text\" }<br>    }<br>  }<br>}<\/pre>\n\n\n\n<p>When Elasticsearch auto-detects a string field, it often creates both <strong>text<\/strong> and <strong>keyword<\/strong> sub-fields \u2014 but doesn\u2019t always get it right for all fields. By explicitly mapping <strong>eventId<\/strong> as <strong>keyword<\/strong>, we ensured:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Values are stored as-is, with no analysis<\/li>\n\n\n\n<li>The field is optimised for exact-match lookups<\/li>\n\n\n\n<li>Storage overhead is reduced<\/li>\n\n\n\n<li>Indexing speed improves<\/li>\n<\/ul>\n\n\n\n<p>Fields genuinely requiring full-text search (like <strong>description<\/strong>) remain as <strong>text<\/strong>. The key is being intentional about which type each field needs.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u2705 The Fix<\/strong> Always define your index mappings explicitly. Correct field types are the foundation of good Elasticsearch performance \u2014 and the cheapest optimization to make.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The Optimized Spring Boot Implementation<\/strong><\/h2>\n\n\n\n<p>Here is what the fully optimized query looks like using the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/client\/java-api-client\/current\/index.html\">Elasticsearch Java client<\/a> in a Spring Boot service. This single method incorporates all four fixes \u2014 term queries, filter clauses, search_after pagination, and correct field targeting:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public SearchResponse&lt;Product&gt; searchActiveEvents(String eventId) throws IOException {<br>    return elasticsearchClient.search(s -&gt; s<br>        .index(\"events_index\")<br>        .query(q -&gt; q<br>            .bool(b -&gt; b<br>                \/\/ Fix #1 &amp; #2: filter (not must) + term (not match)<br>                .filter(f -&gt; f.term(t -&gt; t.field(\"status\").value(\"ACTIVE\")))<br>                .filter(f -&gt; f.term(t -&gt; t.field(\"eventId.keyword\").value(eventId)))<br>            )<br>        )<br>        \/\/ Fix #3: Keyset pagination \u2014 no deep offset scanning<br>        .size(10)<br>        .sort(so -&gt; so.field(f -&gt; f.field(\"timestamp\").order(SortOrder.Desc))),<br>        Product.class<br>    );<br>}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Before vs. After: The Performance Impact<\/strong><\/h2>\n\n\n\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<title>Performance Table<\/title>\n<style>\n    body {\n        font-family: Arial, sans-serif;\n        background-color: #f5f5f5;\n    }\n\n    .table-container {\n        width: 700px;\n        margin: 40px auto;\n        border: 1px solid #ccc;\n        border-radius: 4px;\n        overflow: hidden;\n    }\n\n    table {\n        width: 100%;\n        border-collapse: collapse;\n    }\n\n    thead {\n        background-color: #1f2235;\n        color: white;\n    }\n\n    th, td {\n        padding: 14px 16px;\n        text-align: left;\n        border-bottom: 1px solid #ddd;\n    }\n\n    th {\n        font-weight: 600;\n    }\n\n    tbody tr:nth-child(1) {\n        background-color: #f0f0f0;\n    }\n\n    tbody tr:nth-child(2) {\n        background-color: #f7f7f7;\n    }\n\n    .slow {\n        color: #d32f2f;\n        font-weight: bold;\n    }\n\n    .fast {\n        color: #2e7d32;\n        font-weight: bold;\n    }\n\n    .status {\n        display: flex;\n        align-items: center;\n        gap: 8px;\n        font-weight: 500;\n    }\n\n    .icon {\n        font-size: 16px;\n    }\n\n    .icon.cross {\n        color: #d32f2f;\n    }\n\n    .icon.check {\n        color: #2e7d32;\n    }\n<\/style>\n<\/head>\n<body>\n\n<div class=\"table-container\">\n    <table>\n        <thead>\n            <tr>\n                <th>Scenario<\/th>\n                <th>Response Time<\/th>\n                <th>Status<\/th>\n            <\/tr>\n        <\/thead>\n        <tbody>\n            <tr>\n                <td>Before Optimization (5M+ records)<\/td>\n                <td class=\"slow\">3 \u2013 5 seconds<\/td>\n                <td>\n                    <div class=\"status\">\n                        <span class=\"icon cross\">\u2716<\/span>\n                        Too Slow\n                    <\/div>\n                <\/td>\n            <\/tr>\n            <tr>\n                <td>After Optimization<\/td>\n                <td class=\"fast\">&lt; 500 ms<\/td>\n                <td>\n                    <div class=\"status\">\n                        <span class=\"icon check\">\u2714<\/span>\n                        Production Ready\n                    <\/div>\n                <\/td>\n            <\/tr>\n        <\/tbody>\n    <\/table>\n<\/div>\n\n<\/body>\n<\/html>\n\n\n\n<p>The improvement wasn\u2019t the result of scaling infrastructure, reindexing data, or adding caching layers. It came entirely from writing queries correctly. The data hadn\u2019t changed. The cluster hadn\u2019t changed. Only the query logic changed \u2014 and the impact was immediate and significant.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Key Takeaways: Elasticsearch Performance Best Practices<\/strong><\/h2>\n\n\n\n<p>These are the principles that should guide any Elasticsearch implementation handling large datasets:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Use term queries for exact values. <\/strong>Any field holding an ID, status code, enum, or identifier should use term with .keyword \u2014 never match.<\/li>\n\n\n\n<li><strong>Use filter instead of must for conditional logic. <\/strong>When you\u2019re filtering records rather than ranking them, filter is always the right choice. It skips scoring, enables caching, and reduces per-document work.<\/li>\n\n\n\n<li><strong>Never use deep from\/size pagination on large indices. <\/strong>Replace it with search_after for consistent, scalable pagination performance regardless of dataset size.<\/li>\n\n\n\n<li><strong>Define your mappings explicitly. <\/strong>Do not rely on Elasticsearch\u2019s dynamic mapping. Correct field types are the cheapest and most foundational performance optimisation available.<\/li>\n\n\n\n<li><strong>Test with production-scale data. <\/strong>Elasticsearch query performance characteristics don\u2019t always surface at small data volumes. Always performance-test with realistic record counts.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Need Help Optimising Your Java or Elasticsearch System?<\/strong><\/h2>\n\n\n\n<p>The patterns described in this post are ones our team applies regularly across client engagements. Whether it\u2019s tuning an underperforming search layer, refactoring a slow Spring Boot service, or designing a scalable data architecture from the ground up, Sparksupport\u2019s engineering team has deep hands-on experience delivering results.<\/p>\n\n\n\n<p>Explore what we do:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/sparksupport.com\/java-development\"><strong>Java Development Services<\/strong><\/a> \u2014 Custom Java and Spring Boot solutions for enterprise-grade applications<\/li>\n\n\n\n<li><a href=\"https:\/\/sparksupport.com\/software-development\"><strong>Software Development Services<\/strong><\/a> \u2014 End-to-end development across web, mobile, and backend systems<\/li>\n\n\n\n<li><a href=\"https:\/\/sparksupport.com\/technology-consulting\"><strong>Technology Consulting<\/strong><\/a> \u2014 Architecture reviews, performance audits, and engineering strategy<\/li>\n\n\n\n<li><a href=\"https:\/\/sparksupport.com\/case-studies\"><strong>Case Studies<\/strong><\/a> \u2014 See how we\u2019ve solved real engineering challenges for our clients<\/li>\n\n\n\n<li><a href=\"https:\/\/sparksupport.com\/about\"><strong>About Sparksupport<\/strong><\/a> \u2014 Who we are and how we work<\/li>\n<\/ul>\n\n\n\n<p>Have a performance problem in your Java or Elasticsearch stack? <a href=\"https:\/\/sparksupport.com\/contact\"><strong>Get in touch with our team<\/strong><\/a> \u2014 we\u2019d be glad to take a look.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>External References &amp; Further Reading<\/strong><\/h2>\n\n\n\n<p>For developers looking to go deeper on any of these topics, the following official Elasticsearch documentation pages are the authoritative source:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-term-query.html\">Elasticsearch: term query documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-filter-context.html\">Elasticsearch: Query vs Filter context (must vs filter)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/paginate-search-results.html\">Elasticsearch: Paginate search results (search_after)<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/mapping.html\">Elasticsearch: Explicit field mapping guide<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/client\/java-api-client\/current\/index.html\">Elasticsearch Java API Client documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/spring.io\/projects\/spring-boot\">Spring Boot official documentation<\/a><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>About Sparksupport<\/strong><\/h3>\n\n\n\n<p>Sparksupport is a technology partner helping businesses build, scale, and optimise software systems. Our engineering teams specialise in Java, Spring Boot, cloud architecture, and enterprise-grade application development. We publish practical engineering insights from real project experience \u2014 no filler, no theory, just what actually works in production.<\/p>\n\n\n\n<figure class=\"wp-block-pullquote\"><blockquote><p>Explore Our Pages<\/p><cite><a href=\"https:\/\/sparksupport.com\"><strong>sparksupport.com<\/strong><\/a>&nbsp; \u2022&nbsp; <a href=\"https:\/\/sparksupport.com\/contact\"><strong>Contact Us<\/strong><\/a>&nbsp; \u2022&nbsp; <a href=\"https:\/\/sparksupport.com\/blog\"><strong>Engineering Blog<\/strong><\/a>&nbsp; \u2022&nbsp; <a href=\"https:\/\/sparksupport.com\/case-studies\"><strong>Case Studies<\/strong><\/a><\/cite><\/blockquote><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Elasticsearch running slow on millions of records? Here\u2019s the exact query-level fix our Java engineers applied to achieve a 90% performance improvement in a live<\/p>\n","protected":false},"author":1,"featured_media":5476,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[24],"tags":[],"class_list":["post-5470","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Fix Slow Elasticsearch Queries in Spring Boot<\/title>\n<meta name=\"description\" content=\"Struggling with slow Elasticsearch queries in Spring Boot? Learn proven optimization techniques to reduce response time.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Fix Slow Elasticsearch Queries in Spring Boot\" \/>\n<meta property=\"og:description\" content=\"Struggling with slow Elasticsearch queries in Spring Boot? Learn proven optimization techniques to reduce response time.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-03-26T11:25:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-26T11:47:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2026\/03\/Explore-the-Power-of-AI-PowerApps-1-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"445\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"SparkSupport\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"SparkSupport\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/\"},\"author\":{\"name\":\"SparkSupport\",\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/#\\\/schema\\\/person\\\/b359b1e8bc00b1d71637775f13a9ec44\"},\"headline\":\"How to Fix Slow Elasticsearch Queries in Spring Boot (5 Seconds to Under 500ms)\",\"datePublished\":\"2026-03-26T11:25:27+00:00\",\"dateModified\":\"2026-03-26T11:47:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/\"},\"wordCount\":1620,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/03\\\/Explore-the-Power-of-AI-PowerApps-1-1.png\",\"articleSection\":[\"Articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/\",\"url\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/\",\"name\":\"How to Fix Slow Elasticsearch Queries in Spring Boot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/03\\\/Explore-the-Power-of-AI-PowerApps-1-1.png\",\"datePublished\":\"2026-03-26T11:25:27+00:00\",\"dateModified\":\"2026-03-26T11:47:00+00:00\",\"description\":\"Struggling with slow Elasticsearch queries in Spring Boot? Learn proven optimization techniques to reduce response time.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/#primaryimage\",\"url\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/03\\\/Explore-the-Power-of-AI-PowerApps-1-1.png\",\"contentUrl\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/03\\\/Explore-the-Power-of-AI-PowerApps-1-1.png\",\"width\":800,\"height\":445,\"caption\":\"How to Fix Slow Elasticsearch Queries in Spring Boot\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/fix-slow-elasticsearch-queries-spring-boot\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Fix Slow Elasticsearch Queries in Spring Boot (5 Seconds to Under 500ms)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/\",\"name\":\"SparkSupport Blog\",\"description\":\"SparkSupport Blogs\",\"publisher\":{\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/#organization\",\"name\":\"SparkSupport\",\"url\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/cropped-logo-1.jpg\",\"contentUrl\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/08\\\/cropped-logo-1.jpg\",\"width\":216,\"height\":44,\"caption\":\"SparkSupport\"},\"image\":{\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/#\\\/schema\\\/person\\\/b359b1e8bc00b1d71637775f13a9ec44\",\"name\":\"SparkSupport\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d86cc3c0d188e40e99abec16795ed658b95c89ab15427bd7254315e8115b40b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d86cc3c0d188e40e99abec16795ed658b95c89ab15427bd7254315e8115b40b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d86cc3c0d188e40e99abec16795ed658b95c89ab15427bd7254315e8115b40b?s=96&d=mm&r=g\",\"caption\":\"SparkSupport\"},\"url\":\"https:\\\/\\\/sparksupport.com\\\/blog\\\/author\\\/spark_wp_admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Fix Slow Elasticsearch Queries in Spring Boot","description":"Struggling with slow Elasticsearch queries in Spring Boot? Learn proven optimization techniques to reduce response time.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/","og_locale":"en_US","og_type":"article","og_title":"How to Fix Slow Elasticsearch Queries in Spring Boot","og_description":"Struggling with slow Elasticsearch queries in Spring Boot? Learn proven optimization techniques to reduce response time.","og_url":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/","article_published_time":"2026-03-26T11:25:27+00:00","article_modified_time":"2026-03-26T11:47:00+00:00","og_image":[{"width":800,"height":445,"url":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2026\/03\/Explore-the-Power-of-AI-PowerApps-1-1.png","type":"image\/png"}],"author":"SparkSupport","twitter_card":"summary_large_image","twitter_misc":{"Written by":"SparkSupport","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/#article","isPartOf":{"@id":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/"},"author":{"name":"SparkSupport","@id":"https:\/\/sparksupport.com\/blog\/#\/schema\/person\/b359b1e8bc00b1d71637775f13a9ec44"},"headline":"How to Fix Slow Elasticsearch Queries in Spring Boot (5 Seconds to Under 500ms)","datePublished":"2026-03-26T11:25:27+00:00","dateModified":"2026-03-26T11:47:00+00:00","mainEntityOfPage":{"@id":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/"},"wordCount":1620,"commentCount":0,"publisher":{"@id":"https:\/\/sparksupport.com\/blog\/#organization"},"image":{"@id":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/#primaryimage"},"thumbnailUrl":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2026\/03\/Explore-the-Power-of-AI-PowerApps-1-1.png","articleSection":["Articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/","url":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/","name":"How to Fix Slow Elasticsearch Queries in Spring Boot","isPartOf":{"@id":"https:\/\/sparksupport.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/#primaryimage"},"image":{"@id":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/#primaryimage"},"thumbnailUrl":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2026\/03\/Explore-the-Power-of-AI-PowerApps-1-1.png","datePublished":"2026-03-26T11:25:27+00:00","dateModified":"2026-03-26T11:47:00+00:00","description":"Struggling with slow Elasticsearch queries in Spring Boot? Learn proven optimization techniques to reduce response time.","breadcrumb":{"@id":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/#primaryimage","url":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2026\/03\/Explore-the-Power-of-AI-PowerApps-1-1.png","contentUrl":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2026\/03\/Explore-the-Power-of-AI-PowerApps-1-1.png","width":800,"height":445,"caption":"How to Fix Slow Elasticsearch Queries in Spring Boot"},{"@type":"BreadcrumbList","@id":"https:\/\/sparksupport.com\/blog\/fix-slow-elasticsearch-queries-spring-boot\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sparksupport.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Fix Slow Elasticsearch Queries in Spring Boot (5 Seconds to Under 500ms)"}]},{"@type":"WebSite","@id":"https:\/\/sparksupport.com\/blog\/#website","url":"https:\/\/sparksupport.com\/blog\/","name":"SparkSupport Blog","description":"SparkSupport Blogs","publisher":{"@id":"https:\/\/sparksupport.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sparksupport.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/sparksupport.com\/blog\/#organization","name":"SparkSupport","url":"https:\/\/sparksupport.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/sparksupport.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2019\/08\/cropped-logo-1.jpg","contentUrl":"https:\/\/sparksupport.com\/blog\/wp-content\/uploads\/2019\/08\/cropped-logo-1.jpg","width":216,"height":44,"caption":"SparkSupport"},"image":{"@id":"https:\/\/sparksupport.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/sparksupport.com\/blog\/#\/schema\/person\/b359b1e8bc00b1d71637775f13a9ec44","name":"SparkSupport","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4d86cc3c0d188e40e99abec16795ed658b95c89ab15427bd7254315e8115b40b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4d86cc3c0d188e40e99abec16795ed658b95c89ab15427bd7254315e8115b40b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d86cc3c0d188e40e99abec16795ed658b95c89ab15427bd7254315e8115b40b?s=96&d=mm&r=g","caption":"SparkSupport"},"url":"https:\/\/sparksupport.com\/blog\/author\/spark_wp_admin\/"}]}},"_links":{"self":[{"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/posts\/5470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/comments?post=5470"}],"version-history":[{"count":5,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/posts\/5470\/revisions"}],"predecessor-version":[{"id":5481,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/posts\/5470\/revisions\/5481"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/media\/5476"}],"wp:attachment":[{"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/media?parent=5470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/categories?post=5470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sparksupport.com\/blog\/wp-json\/wp\/v2\/tags?post=5470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}