node-redis
node-redis copied to clipboard
RediSearch result
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:
How te get the result without id AND value , something like this result:
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.
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?
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.