redisnode-redisredis-cluster

Redis Nested Object Search


{
  "name": "Noise-cancelling Bluetooth headphones",
  "description": "Wireless Bluetooth headphones with noise-cancelling technology",
  "connection": {
    "wireless": true,
    "type": "Bluetooth"
  },
  "price": 99.98,
  "stock": 25,
  "colors": [
    "black",
    "silver"
  ],
  "embedding": [0.87, -0.15, 0.55, 0.03]
}

I have seen this object in Redis Search documentation and I'm storing similar object with Hash format. How can I make search on if wireless true return with ft.search? I have tried this one but it gives syntax error

await this.client.ft.search(index, `@colors.wireless:"${wirelessStatus}"`);


Solution

  • I have resolved the issue with keyword search on hashes. The reason why I can't directly use it like below is because Redis example was storing them in JSON format but I'm storing my value in Hash format.

    await this.client.ft.search(index, '@wireless:"${wirelessStatus}');

    So I have updated code like this. It searches wirelessStatus keyword inside related column and I'm storing identifier inside this field to retrieve it.

    await this.client.ft.search(index, '@wireless:"(${wirelessStatus})');