node-redis icon indicating copy to clipboard operation
node-redis copied to clipboard

RediSearch result

Open akelmj opened this issue 1 year ago • 2 comments

Hi,

I use this code to search products:

let products = await redisClient.ft.search(index_name , '@brand:(lg)' , {RETURN: ['$.product_type' , 'priority'] , LIMIT:{from: 0 , size:5}});

The result is:

image

How te get the result without id AND value , something like this result:

image

i use this code to get the result:

products.documents = products.documents.map(x=> { return { "priority" : x.value['priority'] , "product_type" : x.value['$.product_type'] }}); can i get the same result using redisSearch without using extra jsavascript code like i use above?

thanks.

akelmj avatar Aug 31 '22 13:08 akelmj

The reason it's like that (and not a "flat object") is to make sure it'll not override the id property of the document (in case there is one)

The only other solution I can think of is using Symbol, but it's not supported by JSON

@guyroyse @simonprickett WDUT?

leibale avatar Aug 31 '22 14:08 leibale

This is just mimicking the underlying RediSearch implementation, which always returns the key and, optionally, the data within that key (if you specify return in RediSearch with a RETURN 0 you won't get the values). Node Redis should match the behavior of RediSearch—and the rest of Redis and its modules for that matter—as closely as possible.

That said, I certainly see the utility of not returning the keys. But, I think this would be best implemented in RediSearch with some sort of WITHOUTKEYS flag or something like that. Then, Node Redis could mimic that implementation.

guyroyse avatar Aug 31 '22 14:08 guyroyse