Miraclin Technologies
← Back to Blog
ElasticsearchSearch EngineAnalyticsFull-Text SearchELK Stack

Elasticsearch Search Engine 2026: Full-Text Search and Analytics

Miraclin Technologies
Elasticsearch Search Engine 2026: Full-Text Search and Analytics

Elasticsearch Search Engine 2026: Full-Text Search and Analytics

Elasticsearch is the leading distributed search and analytics engine, powering search functionality for applications ranging from e-commerce to log analysis. This guide covers essential Elasticsearch concepts, advanced querying techniques, and optimization strategies for building powerful search solutions.

Elasticsearch Fundamentals

Index and Document Management

// Create index with mapping
PUT /products
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "analyzer": "standard"
      },
      "description": {
        "type": "text",
        "analyzer": "english"
      },
      "price": {
        "type": "float"
      },
      "category": {
        "type": "keyword"
      },
      "tags": {
        "type": "keyword"
      },
      "created_at": {
        "type": "date"
      },
      "location": {
        "type": "geo_point"
      }
    }
  }
}

// Index documents
POST /products/_doc/1
{
  "name": "Wireless Headphones",
  "description": "High-quality wireless headphones with noise cancellation",
  "price": 199.99,
  "category": "electronics",
  "tags": ["audio", "wireless", "premium"],
  "created_at": "2026-12-23T10:00:00Z",
  "location": {
    "lat": 40.7128,
    "lon": -74.0060
  }
}

// Bulk indexing
POST /_bulk
{"index": {"_index": "products", "_id": "2"}}
{"name": "Gaming Mouse", "price": 79.99, "category": "electronics"}
{"index": {"_index": "products", "_id": "3"}}
{"name": "Office Chair", "price": 299.99, "category": "furniture"}

Search Queries

// Basic search
GET /products/_search
{
  "query": {
    "match": {
      "name": "wireless headphones"
    }
  }
}

// Multi-field search
GET /products/_search
{
  "query": {
    "multi_match": {
      "query": "wireless audio",
      "fields": ["name^2", "description", "tags"],
      "type": "best_fields"
    }
  }
}

// Boolean query
GET /products/_search
{
  "query": {
    "bool": {
      "must": [
        {"match": {"category": "electronics"}}
      ],
      "should": [
        {"match": {"tags": "wireless"}},
        {"match": {"tags": "premium"}}
      ],
      "filter": [
        {"range": {"price": {"gte": 50, "lte": 300}}}
      ],
      "must_not": [
        {"match": {"tags": "discontinued"}}
      ]
    }
  }
}

Advanced Query Techniques

Full-Text Search

// Phrase matching
GET /products/_search
{
  "query": {
    "match_phrase": {
      "description": "noise cancellation"
    }
  }
}

// Fuzzy search for typos
GET /products/_search
{
  "query": {
    "fuzzy": {
      "name": {
        "value": "headphons",
        "fuzziness": "AUTO"
      }
    }
  }
}

// Wildcard and regex
GET /products/_search
{
  "query": {
    "wildcard": {
      "name": "*phone*"
    }
  }
}

GET /products/_search
{
  "query": {
    "regexp": {
      "name": ".*[Hh]eadphone.*"
    }
  }
}

Geospatial Queries

// Geo distance query
GET /products/_search
{
  "query": {
    "geo_distance": {
      "distance": "10km",
      "location": {
        "lat": 40.7128,
        "lon": -74.0060
      }
    }
  }
}

// Geo bounding box
GET /products/_search
{
  "query": {
    "geo_bounding_box": {
      "location": {
        "top_left": {
          "lat": 41.0,
          "lon": -75.0
        },
        "bottom_right": {
          "lat": 40.0,
          "lon": -73.0
        }
      }
    }
  }
}

Nested and Parent-Child Queries

// Nested objects mapping
PUT /orders
{
  "mappings": {
    "properties": {
      "customer": {"type": "keyword"},
      "items": {
        "type": "nested",
        "properties": {
          "name": {"type": "text"},
          "price": {"type": "float"},
          "quantity": {"type": "integer"}
        }
      }
    }
  }
}

// Nested query
GET /orders/_search
{
  "query": {
    "nested": {
      "path": "items",
      "query": {
        "bool": {
          "must": [
            {"match": {"items.name": "headphones"}},
            {"range": {"items.price": {"gte": 100}}}
          ]
        }
      }
    }
  }
}

Aggregations and Analytics

Metric Aggregations

// Basic statistics
GET /products/_search
{
  "size": 0,
  "aggs": {
    "avg_price": {
      "avg": {"field": "price"}
    },
    "max_price": {
      "max": {"field": "price"}
    },
    "min_price": {
      "min": {"field": "price"}
    },
    "total_products": {
      "value_count": {"field": "price"}
    },
    "price_stats": {
      "stats": {"field": "price"}
    }
  }
}

Bucket Aggregations

// Terms aggregation
GET /products/_search
{
  "size": 0,
  "aggs": {
    "categories": {
      "terms": {
        "field": "category",
        "size": 10
      },
      "aggs": {
        "avg_price": {
          "avg": {"field": "price"}
        }
      }
    }
  }
}

// Date histogram
GET /products/_search
{
  "size": 0,
  "aggs": {
    "sales_over_time": {
      "date_histogram": {
        "field": "created_at",
        "calendar_interval": "month"
      },
      "aggs": {
        "total_sales": {
          "sum": {"field": "price"}
        }
      }
    }
  }
}

// Range aggregation
GET /products/_search
{
  "size": 0,
  "aggs": {
    "price_ranges": {
      "range": {
        "field": "price",
        "ranges": [
          {"to": 50},
          {"from": 50, "to": 200},
          {"from": 200}
        ]
      }
    }
  }
}

Pipeline Aggregations

// Moving average
GET /sales/_search
{
  "size": 0,
  "aggs": {
    "sales_per_month": {
      "date_histogram": {
        "field": "date",
        "calendar_interval": "month"
      },
      "aggs": {
        "sales": {
          "sum": {"field": "amount"}
        },
        "sales_moving_avg": {
          "moving_avg": {
            "buckets_path": "sales",
            "window": 3,
            "model": "linear"
          }
        }
      }
    }
  }
}

// Derivative aggregation
GET /sales/_search
{
  "size": 0,
  "aggs": {
    "sales_per_month": {
      "date_histogram": {
        "field": "date",
        "calendar_interval": "month"
      },
      "aggs": {
        "sales": {
          "sum": {"field": "amount"}
        },
        "sales_deriv": {
          "derivative": {
            "buckets_path": "sales"
          }
        }
      }
    }
  }
}

Performance Optimization

Index Optimization

// Index settings for performance
PUT /products
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1,
    "refresh_interval": "30s",
    "index.codec": "best_compression",
    "index.mapping.total_fields.limit": 2000
  }
}

// Custom analyzer
PUT /products
{
  "settings": {
    "analysis": {
      "analyzer": {
        "custom_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "stop",
            "snowball"
          ]
        }
      }
    }
  }
}

Query Optimization

// Use filters for exact matches
GET /products/_search
{
  "query": {
    "bool": {
      "must": [
        {"match": {"description": "wireless"}}
      ],
      "filter": [
        {"term": {"category": "electronics"}},
        {"range": {"price": {"gte": 50}}}
      ]
    }
  }
}

// Source filtering
GET /products/_search
{
  "_source": ["name", "price", "category"],
  "query": {"match_all": {}}
}

// Use scroll for large result sets
POST /products/_search?scroll=1m
{
  "size": 1000,
  "query": {"match_all": {}}
}

Caching Strategies

// Request cache
GET /products/_search?request_cache=true
{
  "size": 0,
  "aggs": {
    "categories": {
      "terms": {"field": "category"}
    }
  }
}

// Field data cache settings
PUT /products/_settings
{
  "index.fielddata.cache.size": "40%"
}

Cluster Management

Cluster Configuration

# elasticsearch.yml
cluster.name: production-cluster
node.name: node-1
node.roles: [master, data, ingest]

network.host: 0.0.0.0
http.port: 9200
transport.port: 9300

discovery.seed_hosts: ["node-1", "node-2", "node-3"]
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]

# Memory settings
bootstrap.memory_lock: true

Index Lifecycle Management

// ILM policy
PUT /_ilm/policy/logs_policy
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover": {
            "max_size": "10GB",
            "max_age": "7d"
          }
        }
      },
      "warm": {
        "min_age": "7d",
        "actions": {
          "allocate": {
            "number_of_replicas": 0
          },
          "forcemerge": {
            "max_num_segments": 1
          }
        }
      },
      "cold": {
        "min_age": "30d",
        "actions": {
          "allocate": {
            "number_of_replicas": 0
          }
        }
      },
      "delete": {
        "min_age": "90d"
      }
    }
  }
}

// Apply policy to index template
PUT /_index_template/logs_template
{
  "index_patterns": ["logs-*"],
  "template": {
    "settings": {
      "index.lifecycle.name": "logs_policy",
      "index.lifecycle.rollover_alias": "logs"
    }
  }
}

Application Integration

Node.js Integration

const { Client } = require('@elastic/elasticsearch');

const client = new Client({
  node: 'http://localhost:9200',
  auth: {
    username: 'elastic',
    password: 'password'
  }
});

// Search function
async function searchProducts(query, filters = {}) {
  const body = {
    query: {
      bool: {
        must: [
          {
            multi_match: {
              query,
              fields: ['name^2', 'description', 'tags']
            }
          }
        ],
        filter: []
      }
    },
    aggs: {
      categories: {
        terms: { field: 'category' }
      },
      price_ranges: {
        range: {
          field: 'price',
          ranges: [
            { to: 50 },
            { from: 50, to: 200 },
            { from: 200 }
          ]
        }
      }
    }
  };

  // Add filters
  if (filters.category) {
    body.query.bool.filter.push({
      term: { category: filters.category }
    });
  }

  if (filters.priceRange) {
    body.query.bool.filter.push({
      range: {
        price: {
          gte: filters.priceRange.min,
          lte: filters.priceRange.max
        }
      }
    });
  }

  const response = await client.search({
    index: 'products',
    body
  });

  return {
    hits: response.body.hits.hits,
    total: response.body.hits.total.value,
    aggregations: response.body.aggregations
  };
}

// Autocomplete function
async function autocomplete(query) {
  const response = await client.search({
    index: 'products',
    body: {
      suggest: {
        product_suggest: {
          prefix: query,
          completion: {
            field: 'suggest',
            size: 10
          }
        }
      }
    }
  });

  return response.body.suggest.product_suggest[0].options;
}

Python Integration

from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk

# Initialize client
es = Elasticsearch(
    ['localhost:9200'],
    http_auth=('elastic', 'password'),
    verify_certs=True
)

# Search function
def search_products(query, filters=None):
    body = {
        "query": {
            "bool": {
                "must": [
                    {
                        "multi_match": {
                            "query": query,
                            "fields": ["name^2", "description", "tags"]
                        }
                    }
                ],
                "filter": []
            }
        },
        "aggs": {
            "categories": {
                "terms": {"field": "category"}
            }
        }
    }
    
    if filters:
        if filters.get('category'):
            body["query"]["bool"]["filter"].append({
                "term": {"category": filters['category']}
            })
    
    response = es.search(index="products", body=body)
    return response

# Bulk indexing
def bulk_index_products(products):
    actions = []
    for product in products:
        action = {
            "_index": "products",
            "_source": product
        }
        actions.append(action)
    
    bulk(es, actions)

Monitoring and Maintenance

Cluster Health Monitoring

// Cluster health
GET /_cluster/health

// Node stats
GET /_nodes/stats

// Index stats
GET /products/_stats

// Shard allocation
GET /_cat/shards?v

// Pending tasks
GET /_cluster/pending_tasks

Performance Monitoring

// Query profiling
GET /products/_search
{
  "profile": true,
  "query": {
    "match": {"name": "headphones"}
  }
}

// Hot threads
GET /_nodes/hot_threads

// Field data usage
GET /_nodes/stats/indices/fielddata?fields=*

Security Configuration

Authentication and Authorization

# elasticsearch.yml
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.http.ssl.enabled: true

# Create users and roles
POST /_security/role/product_reader
{
  "indices": [
    {
      "names": ["products"],
      "privileges": ["read"]
    }
  ]
}

POST /_security/user/app_user
{
  "password": "secure_password",
  "roles": ["product_reader"]
}

Index-Level Security

// Document-level security
POST /_security/role/user_data_role
{
  "indices": [
    {
      "names": ["user_data"],
      "privileges": ["read"],
      "query": {
        "term": {
          "user_id": "{{username}}"
        }
      }
    }
  ]
}

Career Opportunities

High-Demand Roles

  • Elasticsearch Engineer: $95,000 - $135,000
  • Search Engineer: $100,000 - $140,000
  • Data Engineer: $105,000 - $145,000
  • DevOps Engineer: $100,000 - $140,000

Essential Skills

  1. Index design and mapping strategies
  2. Advanced querying and aggregations
  3. Performance optimization techniques
  4. Cluster management and scaling
  5. Security implementation
  6. Monitoring and troubleshooting
  7. Application integration
  8. ELK stack proficiency

Conclusion

Elasticsearch is essential for building powerful search and analytics solutions. Master these indexing strategies, query techniques, and optimization practices to create scalable, high-performance search applications. The growing demand for search functionality and data analytics creates excellent opportunities for Elasticsearch specialists.