{
  "schema_version": 2,
  "id": "develop/ai/search-and-query/indexing/schema-definition",
  "title": "Schema definition",
  "url": "https://redis.io/docs/latest/develop/ai/search-and-query/indexing/schema-definition/",
  "summary": "How to define the schema of an index.",
  "aliases": [
    "/develop/interact/search-and-query/indexing/schema-definition",
    "/develop/interact/search-and-query/basic-constructs/schema-definition"
  ],
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-11T15:33:04+01:00",
  "page_type": "content",
  "content_hash": "c3e5ad203629ce9b6399bc6ae98274ed5b94c1ac75d0e91c12c6d466e7282b91",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "An index structure is defined by a schema. The schema specifies the fields, their types, whether they should be indexed or stored, and other additional configuration options. By properly configuring the schema, you can optimize search performance and control the storage requirements of your index.\n\n[code example]\n\nIn this example, a schema is defined for an index named `idx` that will index all hash documents whose keyname starts with `blog:post:`. \nThe schema includes the fields `title`, `content`, `author`, `created_date`, and `views`. The `TEXT` type indicates that the `title` and `content` fields are text-based, the `TAG` type is used for the `author` field, and the `NUMERIC` type is used for the `created_date` and `views` fields. Additionally, a weight of 5.0 is assigned to the `title` field to give it more relevance in search results, and `created_date` is marked as `SORTABLE` to enable sorting based on this field.\n\nYou can learn more about the available field types and options on the [`FT.CREATE`](https://redis.io/docs/latest/commands/ft.create) page."
    },
    {
      "id": "more-schema-definition-examples",
      "title": "More schema definition examples",
      "role": "content",
      "text": "##### Index tags with a separator\n\nIndex books that have a `categories` attribute, where each category is separated by a `;` character.\n\n[code example]\n\n##### Index a single field in multiple ways\n\nIndex the `sku` attribute from a hash as both a `TAG` and as `TEXT`:\n\n[code example]\n\n##### Index documents with multiple prefixes\n\nIndex two different hashes, one containing author data and one containing book data:\n[code example]\n\nIn this example, keys for author data use the key pattern `author:details:<id>`, while keys for book data use the pattern `book:details:<id>`.\n\n##### Only index documents if a field specifies a certain value using `FILTER`\n\nIndex authors whose names start with G:\n\n[code example]\n\nIndex only books that have a subtitle:\n\n[code example]\n\n##### Index a JSON document using a JSONPath expression\n\nIndex a JSON document that has `title` and `categories` fields. The `title` field is indexed as `TEXT` and the `categories` field is indexed as `TAG`.\n\n[code example]\n\n\nYou can learn more about the available field types and options on the [`FT.CREATE`](https://redis.io/docs/latest/commands/ft.create) page."
    }
  ],
  "examples": [
    {
      "id": "overview-ex0",
      "language": "plaintext",
      "code": "FT.CREATE idx \n    ON HASH \n    PREFIX 1 blog:post: \nSCHEMA \n    title TEXT WEIGHT 5.0\n    content TEXT\n    author TAG\n    created_date NUMERIC SORTABLE\n    views NUMERIC",
      "section_id": "overview"
    },
    {
      "id": "more-schema-definition-examples-ex0",
      "language": "plaintext",
      "code": "FT.CREATE books-idx \n    ON HASH \n    PREFIX 1 book:details \nSCHEMA \n    title TEXT \n    categories TAG SEPARATOR \";\"",
      "section_id": "more-schema-definition-examples"
    },
    {
      "id": "more-schema-definition-examples-ex1",
      "language": "plaintext",
      "code": "FT.CREATE idx \n    ON HASH \n    PREFIX 1 blog:post: \nSCHEMA \n    sku AS sku_text TEXT \n    sku AS sku_tag TAG SORTABLE",
      "section_id": "more-schema-definition-examples"
    },
    {
      "id": "more-schema-definition-examples-ex2",
      "language": "plaintext",
      "code": "FT.CREATE author-books-idx \n    ON HASH \n    PREFIX 2 author:details: book:details: \nSCHEMA\n    author_id TAG SORTABLE \n    author_ids TAG \n    title TEXT name TEXT",
      "section_id": "more-schema-definition-examples"
    },
    {
      "id": "more-schema-definition-examples-ex3",
      "language": "plaintext",
      "code": "FT.CREATE g-authors-idx \n    ON HASH \n    PREFIX 1 author:details \n    FILTER 'startswith(@name, \"G\")' \nSCHEMA \n    name TEXT",
      "section_id": "more-schema-definition-examples"
    },
    {
      "id": "more-schema-definition-examples-ex4",
      "language": "plaintext",
      "code": "FT.CREATE subtitled-books-idx\n    ON HASH \n    PREFIX 1 book:details \n    FILTER '@subtitle != \"\"' \nSCHEMA \n    title TEXT",
      "section_id": "more-schema-definition-examples"
    },
    {
      "id": "more-schema-definition-examples-ex5",
      "language": "plaintext",
      "code": "FT.CREATE idx \n    ON JSON \nSCHEMA \n    $.title AS title TEXT \n    $.categories AS categories TAG",
      "section_id": "more-schema-definition-examples"
    }
  ]
}
