Elasticsearch Setup for Search in Mobile Application
Native database search via LIKE '%query%' doesn't work for products with thousands of records: slow, no relevance, no match highlighting, no full-text search with morphology. Elasticsearch solves all these problems, but requires proper server-side setup and smart mobile client integration.
Architecture: Mobile App Never Calls ES Directly
Main rule: mobile client never makes requests directly to Elasticsearch. Always via backend API. Reasons—security (don't expose index structure and credentials), server-side caching possible, load control.
Typical scheme: mobile app → GET /api/search?q=sneakers&category=sport&page=1 → Laravel/Node backend → Elasticsearch → response with pagination and metadata.
Index Configuration
For Russian-language content, analyzer with morphology is mandatory. Use analysis-morphology plugin (from Artifact) or analysis-russian (built into ES). Without morphology, search "krossovki" won't find "krossovok" or "krossovka".
Example field mapping with Russian analyzer:
{
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "russian",
"fields": {
"keyword": { "type": "keyword" }
}
}
}
}
}
keyword field needed for sorting and aggregations—text not suitable.
What Matters for Mobile UX
Suggestions on input (autocomplete). Implement via completion suggester or search_as_you_type field type. Latter simpler to configure and works well for short queries:
"title": {
"type": "search_as_you_type"
}
Requests go on every field change with 300ms debounce. Show max 5-7 suggestions.
Faceted search (filters). ES aggregations let you get product count in each category/brand in one request. In mobile app—bottom sheet with filters, chips values update on each filter change without requery (use cached aggregations).
Relevance and ranking. function_score query lets you boost rating for new products, highly-rated products, or personalized results. Typical e-commerce formula: base text score × popularity boost × date decay function.
Pagination. Standard from/size works only up to 10,000 results (index.max_result_window limit). For cursor pagination use search_after with sort by unique field. In mobile app—infinite scroll without "next page" button.
Offline Search
ES requires network. For basic offline search: cache last results in SQLite, search cache via FTS5 (CREATE VIRTUAL TABLE ... USING fts5). Quality lower but works offline.
Monitoring and Performance
Slow ES queries (over 500ms) need logging. Enable slowlog on server—ES logs queries over threshold. In mobile app show skeleton placeholders while searching, and show "Search taking longer than usual" if request doesn't return in 3 seconds.
Timeline: ES index setup with Russian morphology, search API integration, basic search UI—1-2 weeks. Faceted search, autocomplete, offline cache—3-4 weeks.







