[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# FT.SEARCH\n\n`FT.SEARCH` searches the index with the provided query, and returns the\nspecified values.\n\nFor details on query syntax, see [Query syntax](/memorystore/docs/redis/query-syntax).\n\nSyntax\n------\n\n```\nFT.SEARCH index query\n [NOCONTENT]\n [TIMEOUT timeout]\n [PARAMS nargs name value [ name value ...]]\n [RETURN num field [AS alias] [ field [AS alias] ... ]]\n [LIMIT offset num]\n DIALECT 2\n```\n\n- `index` (required): This index you want to query.\n- `query` (required): This is your query. For details on query syntax, see [Query syntax](/memorystore/docs/redis/query-syntax).\n- `NOCONTENT` (optional): This returns just the document IDs, and excludes the content.\n- `TIMEOUT` (optional): Lets you set a timeout value for the search command.\n- `PARAMS` (optional): The number of key value pairs times two.\n- `RETURN` (optional): Specifies the fields you want to retrieve from your documents, along with any aliases for the returned values. By default, all fields are returned unless the `NOCONTENT` option is set, in which case no fields are returned. If num is set to 0, it behaves the same as `NOCONTENT`.\n- `LIMIT` (optional): Lets you choose pagination with an offset and a number count. If you don't use this parameter, the default is `LIMIT 0 10`, which returns at most 10 keys.\n- `DIALECT 2` (optional): Specifies your dialect. The only supported dialect is dialect 2.\n\n### Command return\n\n- This command returns an array or an error message. The elements of the\n returned array represent the best matched results of the query. Each array\n element has the following:\n\n- The entry hash key\n\n- An array of the following:\n\n - Key value: \\[$score_as \\] score_value\n - Distance value\n - Attribute name\n - Vector value\n\n If `NOCONTENT` is used, the array elements consist of just the document IDs.\n\nExample #1: Simple vector search query\n--------------------------------------\n\nFor this example, assume we're building a property searching index where customers can search properties based on some features. Assume we have a list of properties with the following attributes:\n\n- Description - vector embedding for given property.\n- Other fields - each property can have other metadata as well. However, for simplicity, other fields are ignored in this example.\n\nAt first, we create an HNSW index with the description as a vector field using the `FT.CREATE` command: \n\n```\nFT.CREATE idx SCHEMA description VECTOR HNSW 6 TYPE FLOAT32 DIM 3 DISTANCE_METRIC L2\n```\n\nNow we can insert a few properties (this can be done prior to index creation as well) using the HSET command: \n\n```\nHSET p1 description \"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80?\"\nHSET p2 description \"\\x00\\x00\\x00\\x00\\x00\\x00\\x80?\\x00\\x00\\x00\\x00\"\nHSET p3 description \"\\x00\\x00\\x80?\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\"\nHSET p4 description \"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80?\"\nHSET p5 description \"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80?\"\n```\n\nNow we can perform queries using the FT.SEARCH command. The following query returns up to five of the most similar properties to the provided query vector: \n\n```\nFT.SEARCH idx \"*=\u003e[KNN 5 @description $query_vector]\" PARAMS 2 query_vector \"\\xcd\\xccL?\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\" DIALECT 2\n```\n\nReturned result: \n\n```\n 1) (integer) 5\n 2) p5\n 3) 1) __description_score\n 2) 1.6400001049\n 3) description\n 4) \\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80?\n 4) p4\n 5) 1) __description_score\n 2) 1.6400001049\n 3) description\n 4) \\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80?\n 6) p2\n 7) 1) __description_score\n 2) 1.6400001049\n 3) description\n 4) \\x00\\x00\\x00\\x00\\x00\\x00\\x80?\\x00\\x00\\x00\\x00\n 8) p1\n 9) 1) __description_score\n 2) 1.6400001049\n 3) description\n 4) \\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80?\n10) p3\n11) 1) __description_score\n 2) 0.0399999953806\n 3) description\n 4) \\x00\\x00\\x80?\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\n```\n\n### Code Sample\n\n### Python\n\n```\n# Before running, ensure you have installed redis-py:\n# pip install redis\n\nimport redis\nclient = redis.Redis(host='your_server_host', port=6379)\nresult = client.execute_command('FT.SEARCH', 'idx', '*=\u003e[KNN 5 @description $query_vector]', 'PARAMS', '2', 'query_vector', '\"\\xcd\\xccL?\\x00\\x00\\x00\\x00\"', 'DIALECT', '2')\nprint(result)\n```\n\n### NodeJS\n\n```\n# Before running, ensure you have installed ioredis:\n# npm install ioredis\n\nconst Redis = require(\"ioredis\");\nconst redis = new Redis(6379, \"your_server_host\")\nredis.call(\"FT.SEARCH\", \"idx\", \"*=\u003e[KNN 5 @description $query_vector]\", \"PARAMS\", \"2\", \"query_vector\", \"\\xcd\\xccL?\\x00\\x00\\x00\\x00\\x00\\x00\", \"DIALECT\", \"2\").then(result =\u003e {\nconsole.log(result);\nredis.disconnect();\n});\n```\n\n### CLI\n\n```\n# Before running, ensure you have install redis-cli\n\nredis-cli -h your_server_host -p 6379 FT.SEARCH idx \"(*)=\u003e[KNN 5 @description $query_vector]\" PARAMS 2 query_vector \"\\xcd\\xccL?\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\" DIALECT 2\n```\n\nExample #2: Vector search with [hybrid queries](/memorystore/docs/redis/query-syntax#hybrid-queries)\n----------------------------------------------------------------------------------------------------\n\nFor this example we will do a [hybrid query](/memorystore/docs/redis/query-syntax#hybrid-queries) by using an additional two attributes named city and price:\n\n- Description - vector embedding for given property.\n- City - name of the city.\n- Price - cost of the property.\n\nAt first, we create an index with the description as a vector field, city as a tag field, price as a numeric field: \n\n```\nFT.CREATE idx SCHEMA description VECTOR HNSW 6 TYPE FLOAT32 DIM 3 DISTANCE_METRIC L2 city TAG price NUMERIC\n```\n\nNow, we can insert a few properties (this can be done prior to index creation as well): \n\n```\nHSET p1 description \"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80?\" city \"NEW YORK\" price 500000\nHSET p2 description \"\\x00\\x00\\x00\\x00\\x00\\x00\\x80?\\x00\\x00\\x00\\x00\" city \"NEW JERSEY\" price 400000\nHSET p3 description \"\\x00\\x00\\x80?\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\" city \"BANGALORE\" price 60000\nHSET p4 description \"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80?\" city \"NEW YORK\" price 600000\nHSET p5 description \"\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80?\" city \"BANGALORE\" price 75000\n```\n\nNow, we can perform queries. The following query returns up to five of the most similar properties to the provided query vector, filtering only to those in BANGALORE priced less than 100000: \n\n```\nFT.SEARCH idx \"(@city:{BANGALORE} @price:[-inf 100000])=\u003e[KNN 5 @description $query_vector]\" PARAMS 2 query_vector \"\\xcd\\xccL?\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\" DIALECT 2\n```\n\nReturned result: \n\n```\n1) (integer) 2\n2) p5\n3) 1) __description_score\n 2) 1.6400001049\n 3) city\n 4) BANGALORE\n 5) price\n 6) 75000\n 7) description\n 8) \\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80?\n4) p3\n5) 1) __description_score\n 2) 0.0399999953806\n 3) city\n 4) BANGALORE\n 5) price\n 6) 60000\n 7) description\n 8) \\x00\\x00\\x80?\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\n```\n\nRefer to [Query syntax](/memorystore/docs/redis/query-syntax) for details on the filter query format.\n\n### Code Sample\n\n### Python\n\n```\n# Before running, ensure you have installed redis-py:\n# pip install redis\n\nimport redis\nclient = redis.Redis(host='your_server_host', port=6379)\nresult = client.execute_command('FT.SEARCH', 'idx', '(@city:{BANGALORE} @price:[-inf 100000])=\u003e[KNN 5 @description $query_vector]', 'PARAMS', '2', 'query_vector', '\"\\xcd\\xccL?\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\"', 'DIALECT', '2')\nprint(result)\n```\n\n### NodeJS\n\n```\n# Before running, ensure you have installed ioredis:\n# npm install ioredis\n\nconst Redis = require(\"ioredis\");\nconst redis = new Redis(6379, \"your_server_host\")\nredis.call(\"FT.SEARCH\", \"idx\", \"(@city:{BANGALORE} @price:[-inf 100000])=\u003e[KNN 5 @description $query_vector]\", \"PARAMS\", \"2\", \"query_vector\", \"\\xcd\\xccL?\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\", \"DIALECT\", \"2\").then(result =\u003e {\nconsole.log(result);\nredis.disconnect();\n});\n```\n\n### CLI\n\n```\n# Before running, ensure you have install redis-cli\n\nredis-cli -h your_server_host -p 6379 FT.SEARCH idx \"(@city:{BANGALORE} @price:[-inf 100000])=\u003e[KNN 5 @description $query_vector]\" PARAMS 2 query_vector \"\\xcd\\xccL?\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\" DIALECT 2\n```"]]