redis / node-redis

Redis Node.js client
https://redis.js.org/
MIT License
16.79k stars 1.86k forks source link

RediSearch result #2247

Open akelmj opened 1 year ago

akelmj commented 1 year ago

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.

leibale commented 1 year ago

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?

guyroyse commented 1 year ago

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.