Why RediSearch Can Outperform Elasticsearch: Low Memory, High Speed
The article introduces Redis's official search module RediSearch, compares its memory usage and query performance against Elasticsearch, presents benchmark results showing faster indexing and four‑times higher throughput, and provides step‑by‑step installation, index commands, and Java integration examples.
RediSearch is a Redis module that adds full‑text search, secondary indexes, and query capabilities. It stores data in compressed inverted indexes, allowing low memory consumption and fast index construction. The author notes that RediSearch can replace Elasticsearch for simple use cases, though Chinese pinyin plugins are still missing.
RediSearch Overview
RediSearch provides text tokenization, aggregation, stop‑words, synonyms, spell checking, result sorting, tag queries, vector similarity, and Chinese segmentation. The latest version (2.x) improves throughput and latency by 2.4× over 1.6.
Comparison with Elasticsearch
On a low‑spec 2‑core, 4 GB server, RediSearch consumes less than 100 MB of memory, while Elasticsearch requires at least 1 GB. In the official index‑build benchmark, RediSearch completes in 221 seconds versus Elasticsearch's 349 seconds (58 % faster). In a query‑performance test with 32 concurrent clients, RediSearch achieves 12.5 K ops/sec compared to Elasticsearch's 3.1 K ops/sec, a four‑fold increase, and slightly lower latency (8 ms vs 10 ms).
Installation
For RediSearch 2.0+, the recommended deployment is the redis/redis-stack-server:latest Docker image:
docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latestSet a password if needed:
docker run -e REDIS_ARGS="--requirepass redis-stack" redis/redis-stack:latestVerify the module with:
redis-cli -h localhost
> MODULE list
... "name" "search" "ver" "20809" ...Index Operations
Create Index
FT.CREATE idx:goods ON HASH PREFIX 1 "goods:" LANGUAGE chinese SCHEMA goodsName TEXT SORTABLECreates an index named idx:goods on hash keys with prefix goods:.
Enables Chinese language analysis.
Defines goodsName as a sortable text field.
Add source data:
hset goods:1001 goodsName 小米手机
hset goods:1002 goodsName 华为手机Search Index
FT.SEARCH idx:goods "手机"Returns matching documents with their goodsName fields.
Inspect Index
FT.INFO idx:goodsDelete Index
FT.DROPINDEX idx:goodsOnly removes the index definition; the underlying hash data remains.
Java Integration with Jedis
Jedis 4.0+ includes native RediSearch support. Example bean creation:
@Bean
public UnifiedJedis unifiedJedis(GenericObjectPoolConfig jedisPoolConfig) {
if (StringUtils.isNotEmpty(password)) {
return new JedisPooled(jedisPoolConfig, host, port, timeout, password, database);
} else {
return new JedisPooled(jedisPoolConfig, host, port, timeout, null, database);
}
}Creating an index definition in Java:
Schema schema = new Schema()
.addSortableTextField("goodsName", 1.0)
.addSortableTagField("tag", "|");
IndexDefinition rule = new IndexDefinition(IndexDefinition.Type.HASH)
.setPrefixes("idx:goods")
.setLanguage("chinese");
client.ftCreate(idxName, IndexOptions.defaultOptions().setDefinition(rule), schema);Adding source data:
public boolean addGoodsIndex(String keyPrefix, Goods goods) {
Map<String, String> hash = MyBeanUtil.toMap(goods);
hash.put("_language", "chinese");
client.hset("idx:goods" + goods.getGoodsId(), hash);
return true;
}Performing a Chinese search with pagination and optional sorting:
public SearchResult search(String goodsIdxName, SearchObjVO searchObjVO, Page<SearchPageGoodsVO> page) {
String keyword = searchObjVO.getKeyword();
String queryKey = String.format("@goodsName:(%s)", keyword);
Query q = new Query(queryKey);
if (StringUtils.isNotBlank(searchObjVO.getSidx())) {
q.setSortBy(searchObjVO.getSidx(), Constants.SORT_ASC.equals(searchObjVO.getOrder()));
}
q.setLanguage("chinese");
q.limit((int) page.offset(), (int) page.getSize());
return client.ftSearch(goodsIdxName, q);
}Final Thoughts
RediSearch offers easy installation, low memory footprint, and fast queries, making it suitable for many projects. However, cluster support is currently limited to Redis Enterprise, and the open‑source version lacks this capability. For large‑scale production use, the author advises caution.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Tech Enthusiast
Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
