0Pricing
Redis Caching & Messaging (Pub/Sub, Streams) · Lección

RediSearch para búsqueda de texto completo

Implemente potentes capacidades de búsqueda de texto completo sobre datos de Redis para mejorar las funciones de sus aplicaciones.

RediSearch para búsqueda de texto completo es una lección gratuita de Redis Caching & Messaging (Pub/Sub, Streams) en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Redis Caching & Messaging (Pub/Sub, Streams), y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Redis Caching & Messaging (Pub/Sub, Streams) incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

Unlock Powerful Search

Welcome! In this lesson, we'll dive into RediSearch, a powerful Redis module. It transforms Redis into a robust, real-time search engine.

RediSearch allows you to perform fast, complex full-text searches directly on your Redis data, enhancing your application's features significantly.

RediSearch: A Redis Module

RediSearch isn't part of Redis's core functionality; it's an add-on module. Redis modules extend Redis with new data types and commands.

Think of it as adding a specialized search engine feature directly into your Redis instance, making it incredibly efficient for search operations.

Creating Your First Index

Before you can search, you need to define an index. An index tells RediSearch which fields in your data (typically Redis Hashes) are searchable and how.

The FT.CREATE command is used to set up this schema. Let's create an index named myProductIndex with title and description text fields.

FT.CREATE myProductIndex SCHEMA title TEXT WEIGHT 5.0 description TEXT

Adding Documents to the Index

Once your index is defined, you can start adding documents to it. RediSearch indexes Redis Hashes, so you'll first store your data as a Hash, then add it to the index using FT.ADD.

The score (e.g., 1.0) influences relevance ranking.

HSET product:1 title "RediSearch Guide" description "A comprehensive guide to full-text search with Redis modules." 
HSET product:2 title "Redis Caching Strategies" description "Learn advanced caching patterns using Redis." 
FT.ADD myProductIndex product:1 1.0 FIELDS title "RediSearch Guide" description "A comprehensive guide to full-text search with Redis modules." 
FT.ADD myProductIndex product:2 1.0 FIELDS title "Redis Caching Strategies" description "Learn advanced caching patterns using Redis."

Performing Basic Searches

Now that we have data indexed, let's perform a simple full-text search using the FT.SEARCH command.

You just specify the index name and your query term. RediSearch will look for the term across all indexed text fields.

FT.SEARCH myProductIndex "search" 
FT.SEARCH myProductIndex "Redis"

Field-Specific Searches

Sometimes you need to search only within a specific field. RediSearch allows you to target your queries using the @field:term syntax.

This helps you get more precise results, for example, by searching only in the title field.

FT.SEARCH myProductIndex "@title:Redis" 
FT.SEARCH myProductIndex "@description:guide"

Prefix and Phrase Searches

RediSearch supports advanced query syntax for more flexible searches. You can use prefix searches (e.g., red* for anything starting with 'red') or search for exact phrases.

Exact phrases are enclosed in double quotes.

FT.SEARCH myProductIndex "red*" 
FT.SEARCH myProductIndex "\"full-text search\""

Using Tag Fields for Filtering

For exact filtering, like categorizing items, RediSearch offers TAG fields. These are optimized for checking exact matches rather than full-text relevance.

Let's add a category tag field and demonstrate how to query it. We'll need a new index or to alter an existing one, but for simplicity, imagine it's part of myProductIndex.

FT.CREATE booksIdx SCHEMA title TEXT author TAG 
FT.ADD booksIdx book:1 1.0 FIELDS title "Redis Essentials" author "John Doe, Jane Smith" 
FT.ADD booksIdx book:2 1.0 FIELDS title "Advanced Redis" author "Jane Smith" 
FT.SEARCH booksIdx "@author:{John Doe}" 
FT.SEARCH booksIdx "@author:{Jane Smith|John Doe}"

Quick Check

You want to create a RediSearch index named articles with two fields:

  • headline: a text field for full-text search.
  • topic: a tag field for exact topic filtering.

Which command correctly creates this index?

RediSearch: Powerful Search in Redis

In this lesson, you learned how RediSearch extends Redis with powerful full-text search capabilities.

  • We covered creating an index with a schema using FT.CREATE.
  • You saw how to add documents with FT.ADD and perform basic searches using FT.SEARCH.
  • We explored field-specific queries, prefix searches, phrase searches, and the use of TAG fields for exact filtering.

RediSearch is a fantastic tool for adding robust search features directly to your Redis applications, making data retrieval faster and more flexible!

Preguntas frecuentes

¿La lección «RediSearch para búsqueda de texto completo» es gratis?

Sí — el texto completo de «RediSearch para búsqueda de texto completo» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Redis Caching & Messaging (Pub/Sub, Streams), actualiza a CoddyKit PRO. El curso de Redis Caching & Messaging (Pub/Sub, Streams) incluye 4 lecciones en total.

¿Qué aprenderé en «RediSearch para búsqueda de texto completo»?

Implemente potentes capacidades de búsqueda de texto completo sobre datos de Redis para mejorar las funciones de sus aplicaciones. Practicas Redis Caching & Messaging (Pub/Sub, Streams) con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Redis Caching & Messaging (Pub/Sub, Streams)?

No se requiere experiencia previa. Redis Caching & Messaging (Pub/Sub, Streams) en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.

¿Cuánto tiempo toma la lección «RediSearch para búsqueda de texto completo»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Redis Caching & Messaging (Pub/Sub, Streams)?

Sí. Cada lección de Redis Caching & Messaging (Pub/Sub, Streams) incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Descripción general de los módulos de Redis
  2. RediSearch para búsqueda de texto completo
  3. Fundamentos de RedisJSON y RedisGraph
  4. Series temporales con RedisTimeSeries
← Volver a Redis Caching & Messaging (Pub/Sub, Streams)