Why RediSearch Beats Elasticsearch on Low‑End Servers: A Hands‑On Comparison
This article introduces RediSearch, compares its memory usage and query performance with Elasticsearch on modest hardware, shows installation steps, demonstrates core index commands and Java integration, and concludes with practical advice on using RediSearch as a lightweight full‑text search engine.
RediSearch Overview
RediSearch is a Redis module that provides query, secondary index, and full‑text search capabilities. Users first declare an index (similar to an Elasticsearch index) and then query data using RediSearch's query language. It uses compressed inverted indexes, enabling low memory consumption and fast index construction.
The latest version supports rich query features such as basic text tokenization, aggregation, stop‑words, synonyms, spell checking, result sorting, tag queries, vector similarity, and Chinese tokenization.
This open‑source project may be useful for you; the mall project is a SpringBoot3 + JDK 17 + Vue e‑commerce system with Dockerized deployment, supporting multiple modules and micro‑service architecture.
Comparison with Elasticsearch
Basic Hardware
Data Source
RediSearch Configuration
Elasticsearch Configuration
Version
Index Build Test
In the official index‑build benchmark, RediSearch completed the task in 221 seconds, beating Elasticsearch's 349 seconds—a 58% improvement.
Query Performance Test
After loading data into the index, a load‑generator with 32 clients performed two‑term search queries. RediSearch achieved 12.5K ops/sec, while Elasticsearch reached only 3.1K ops/sec—about four times faster. Latency was also slightly better (8 ms vs. 10 ms).
RediSearch 2.0+ further improves throughput and latency by 2.4× compared with version 1.6.
RediSearch Installation
For the latest RediSearch 2.0, the recommended approach is to deploy the
redis-stack-serverDocker image.
<code>docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latest</code>Set a login password:
<code>// Set login password
docker run -e REDIS_ARGS="--requirepass redis-stack" redis/redis-stack:latest</code>Verify the
searchmodule is loaded via
redis-cli:
<code>redis-cli -h localhost
> MODULE list
...
1) "name"
2) "search"
3) "ver"
4) "20809"
5) "path"
6) "/opt/redis-stack/lib/redisearch.so"
...</code>Index Operations
FT.CREATE – Create Index
<code>> FT.CREATE idx:goods on hash prefix 1 "goods:" language chinese schema goodsName text sortable
"OK"
</code>FT.CREATE: create index command
idx:goods: index name
on hash: index data type
prefix 1 "goods:": target hash key prefix
language chinese: enable Chinese tokenization
schema goodsName text sortable: define a sortable text field
Add source data with
HSET:
<code>hset goods:1001 goodsName 小米手机
hset goods:1002 goodsName 华为手机
</code>FT.SEARCH – Query Index
<code>> FT.SEARCH idx:goods1 "手机"
1) "2"
2) "goods:1001"
3) 1) "goodsName"
2) "\xe5\xb0\x8f\xe7\xb1\xb3\xe6\x89\x8b\xe6\x9c\xba"
4) "goods:1002"
5) 1) "goodsName"
2) "\xe5\x8d\x8e\xe4\xb8\xba\xe6\x89\x8b\xe6\x9c\xba"
</code>FT.INFO – Get Index Info
<code>> FT.INFO idx:goods
1) "index_name"
2) "idx:goods1"
3) "index_options"
4) (empty list or set)
5) "index_definition"
6) 1) "key_type"
2) "HASH"
3) "prefixes"
4) 1) "goods:"
7) "default_language"
8) "chinese"
...</code>FT.DROPINDEX – Delete Index
<code>> FT.DROPINDEX idx:goods1
"OK"
</code>To delete indexed data, simply remove the associated hash keys with
DEL.
Using RediSearch from Java
With Jedis 4.0+ the RediSearch commands are natively supported. Create a Jedis client bean:
<code>@Bean
public UnifiedJedis unifiedJedis(GenericObjectPoolConfig jedisPoolConfig) {
UnifiedJedis client;
if (StringUtils.isNotEmpty(password)) {
client = new JedisPooled(jedisPoolConfig, host, port, timeout, password, database);
} else {
client = new JedisPooled(jedisPoolConfig, host, port, timeout, null, database);
}
return client;
}
</code>Create an index:
<code>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);
</code>Add source data:
<code>public boolean addGoodsIndex(String keyPrefix, Goods goods) {
Map<String, String> hash = MyBeanUtil.toMap(goods);
hash.put("_language", "chinese");
client.hset("idx:goods" + goods.getGoodsId(), MyBeanUtil.toMap(goods));
return true;
}
</code>Perform a Chinese search:
<code>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);
String sort = searchObjVO.getSidx();
String order = searchObjVO.getOrder();
if (StringUtils.isNotBlank(sort)) {
q.setSortBy(sort, Constants.SORT_ASC.equals(order));
}
q.setLanguage("chinese");
q.limit((int) page.offset(), (int) page.getSize());
return client.ftSearch(goodsIdxName, q);
}
</code>Final Thoughts
RediSearch is a relatively new full‑text search engine that quickly gained attention thanks to Redis's popularity. It offers easy installation, low memory footprint, and high query speed, making it suitable for many projects.
However, the open‑source version currently lacks robust support for Redis Cluster; only the enterprise edition provides a cluster solution. For large‑scale production use, careful evaluation is recommended.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
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.