Ask Your Question

What is the method for utilizing ft.aggregate in node-redis?

asked 2021-06-20 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-11-24 07:00:00 +0000

djk gravatar image

To utilize ft.aggregate method in node-redis, follow these steps:

  1. Require the redis module in your Node.js application:
const redis = require('redis');
  1. Create a Redis client instance:
const client = redis.createClient();
  1. Use the ft.aggregate method on the Redis client instance to execute a full-text search aggregate command. The syntax for using the method is as follows:
client.ft_aggregate(index, query [, options], [callback]);
  • The index parameter specifies the name of the Redis search index to aggregate on.
  • The query parameter specifies the query for the aggregate command.
  • The options parameter specifies additional options (if any) such as MAX, SORTBY, LIMIT, etc. The options are provided as an object.
  • The callback parameter is an optional callback function that is executed after the aggregate command is executed.

For example, to aggregate a search query for documents containing the term "apple" in the "fruit" field:

client.ft_aggregate('myIndex', 'apple', { APPLY: ['@fruit'] }, function(err, results) {
  if (err) {
    throw err;

Here, the APPLY option is used to specify the fields to include in the aggregate results.

  1. Finally, close the Redis client connection once you're done:
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2021-06-20 11:00:00 +0000

Seen: 15 times

Last updated: Nov 24 '22