← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Elasticsearch

Search PHP 5.0+ Advanced
debt(d7/e7/b7/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints note automated=no and tools like laravel-scout/kibana don't flag misuse automatically. Slow LIKE queries or bad mappings only surface under load or via careful profiling/review — not caught by a linter or compiler.

e7 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7). The quick_fix describes a non-trivial integration: adding Elasticsearch, defining mappings, setting up queue-based sync workers, and replacing DB queries with ES queries across multiple layers. This is a significant architectural addition touching models, queues, and query logic across files.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7). Elasticsearch is a distributed external system that shapes indexing strategy, data sync, mapping decisions, and query design for the lifetime of the application. It applies to both web and CLI contexts, and every future search feature is constrained by the initial ES schema and sync architecture.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap (a documented gotcha most devs eventually learn)' (t5). The common_mistakes list several real gotchas — auto-mapping guessing types incorrectly, text vs keyword field confusion, filter vs query context performance — these are well-documented but frequently tripped over by developers new to Elasticsearch, matching the t5 anchor well.

About DEBT scoring →

Also Known As

ES Elastic inverted index full-text search engine

TL;DR

A distributed full-text search engine — inverted indexes enable sub-second keyword and relevance-ranked search across millions of documents.

Explanation

Elasticsearch stores documents as JSON in an inverted index — each unique term maps to the documents containing it. Queries: match (full-text), term (exact), bool (combine queries), range (numeric/date ranges), and aggregations (faceted counts). Relevance scoring uses BM25 by default. PHP clients: ruflin/elastica, elastic/elasticsearch-php. Alternatives: Meilisearch (simpler setup, instant search), Typesense (typo-tolerant), OpenSearch (AWS fork). For PHP apps with moderate search needs, Meilisearch is often simpler to operate.

Diagram

flowchart TD
    DOC[Document - JSON] --> INDEX[(Index<br/>like a DB table)]
    INDEX --> SHARDS[Shards<br/>split for scale]
    SHARDS --> REPLICAS[Replica shards<br/>for redundancy]
    subgraph Query Flow
        SEARCH[Search request] --> COORD[Coordinating node]
        COORD --> ALL[Query all shards in parallel]
        ALL --> MERGE[Merge and rank results]
        MERGE --> TOP[Return top N hits]
    end
    subgraph Indexing
        PHP_DOC[PHP sends doc] --> INVERTED[Build inverted index<br/>token to doc list]
    end
style INDEX fill:#6e40c9,color:#fff
style COORD fill:#1f6feb,color:#fff
style TOP fill:#238636,color:#fff

Common Misconception

Elasticsearch is only for large scale — it's a solid choice for any app needing full-text search, faceted filtering, or complex aggregations that a database cannot handle efficiently.

Why It Matters

LIKE '%keyword%' on a million-row table takes seconds; Elasticsearch returns results in milliseconds regardless of corpus size — it transforms search from a bottleneck to a feature.

Common Mistakes

  • High-cardinality keyword fields not mapped as 'keyword' type — text fields are analysed and tokenised; exact values need keyword type.
  • Storing large binary or irrelevant data in Elasticsearch — only index what needs to be searched, store everything else in the primary database.
  • Not defining mappings before indexing — auto-mapping guesses types and often maps numbers as text.
  • Querying without a filter context for exact matches — filters are cached and much faster than queries for boolean conditions.

Code Examples

✗ Vulnerable
// Auto-mapping leads to wrong type inferences:
$client->index(['index' => 'products', 'body' => [
    'price' => '19.99',    // Auto-mapped as text! Cannot range query
    'in_stock' => 'true',  // Auto-mapped as text! Cannot boolean filter
    'description' => 'Great product',
]]);
// Range query: {"range":{"price":{"gte":10}}} — fails silently on text field
✓ Fixed
// Explicit mapping before indexing:
$client->indices()->putMapping(['index' => 'products', 'body' => [
    'properties' => [
        'name'        => ['type' => 'text'],          // Analysed for full-text
        'name_exact'  => ['type' => 'keyword'],        // Exact match/aggregation
        'price'       => ['type' => 'float'],          // Numeric range queries
        'in_stock'    => ['type' => 'boolean'],
        'description' => ['type' => 'text'],
        'tags'        => ['type' => 'keyword'],
    ]
]]);

Added 15 Mar 2026
Edited 22 Mar 2026
Views 62
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 2 pings T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 2 pings T 0 pings F 3 pings S 3 pings S 3 pings M 1 ping T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 1 ping M 0 pings T 2 pings W 1 ping T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Scrapy 11 Amazonbot 9 Perplexity 5 SEMrush 5 Google 4 Ahrefs 4 Majestic 2 Unknown AI 2 Claude 1 Meta AI 1 Bing 1 Qwen 1 Sogou 1 PetalBot 1
crawler 45 crawler_json 3
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: High
⚡ Quick Fix
Use Elasticsearch for full-text search and faceted filtering — let PHP handle business logic and use Elasticsearch only for search; sync data via queue workers, not inline in HTTP requests
📦 Applies To
PHP 5.0+ web cli laravel
🔗 Prerequisites
🔍 Detection Hints
LIKE '%term%' full-text search on large tables; no faceted filtering; slow search degrading with data growth; MySQL FULLTEXT at its limits
Auto-detectable: ✗ No laravel-scout elasticsearch-php kibana
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: Medium ✗ Manual fix Fix: High Context: File Tests: Update


✓ schema.org compliant