> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a Metadata Index

> Use this endpoint to create a metadata index for a specific entity type. Metadata indexes improve query performance when filtering or searching by custom metadata fields.



## OpenAPI

````yaml /en/openapi/v3-current/ledger.yaml post /v1/settings/metadata-indexes/entities/{entity_name}
openapi: 3.1.0
info:
  title: Midaz Ledger API
  description: >-
    Complete API reference for Midaz Ledger services including organization
    management, ledger operations, assets, segments, portfolios, accounts,
    account types, transactions, operations, balances, operation routes,
    transaction routes, and metadata indexes.
  version: 3.7.1
servers:
  - url: https://ledger.sandbox.lerian.net
security: []
tags:
  - name: Organizations API
  - name: Ledgers API
  - name: Assets API
  - name: Segments API
  - name: Portfolios API
  - name: Account Types API
  - name: Accounts API
  - name: Balances API
  - name: Transactions API
  - name: Operations API
  - name: Operation Routes API
  - name: Transaction Routes API
  - name: Metadata Indexes API
paths:
  /v1/settings/metadata-indexes/entities/{entity_name}:
    post:
      tags:
        - Metadata Indexes API
      summary: Create a Metadata Index
      description: >-
        Use this endpoint to create a metadata index for a specific entity type.
        Metadata indexes improve query performance when filtering or searching
        by custom metadata fields.
      parameters:
        - $ref: '#/components/parameters/EntityName'
        - $ref: '#/components/parameters/Authorization'
        - $ref: '#/components/parameters/ContentType'
        - $ref: '#/components/parameters/XRequestId'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMetadataIndexRequest'
            example:
              metadataKey: tier
              unique: false
              sparse: true
        required: true
      responses:
        '201':
          description: >-
            Indicates that the metadata index was successfully created and the
            operation was completed as expected.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetadataIndexResponse'
              example:
                indexName: metadata.tier_1
                entityName: transaction
                metadataKey: tier
                unique: false
                sparse: true
          headers: {}
        '400':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorFormat'
              examples:
                Error0009:
                  $ref: '#/components/examples/Error0009'
                Error0047:
                  $ref: '#/components/examples/Error0047'
                Error0132:
                  $ref: '#/components/examples/Error0132'
                Error0134:
                  $ref: '#/components/examples/Error0134'
                Error0135:
                  $ref: '#/components/examples/Error0135'
                Error0136:
                  $ref: '#/components/examples/Error0136'
                Error0138:
                  $ref: '#/components/examples/Error0138'
          headers: {}
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorFormat'
              examples:
                Error0041:
                  $ref: '#/components/examples/Error0041'
                Error0042:
                  $ref: '#/components/examples/Error0042'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorFormat'
              examples:
                Error0043:
                  $ref: '#/components/examples/Error0043'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorFormat'
              examples:
                Error0046:
                  $ref: '#/components/examples/Error0046'
      security:
        - bearer: []
components:
  parameters:
    EntityName:
      name: entity_name
      in: path
      description: >-
        The name of the entity for which the metadata index will be created or
        managed.
      required: true
      example: transaction
      schema:
        type: string
        enum:
          - organization
          - ledger
          - asset
          - segment
          - portfolio
          - account
          - transaction
          - operation
          - account_type
          - operation_route
          - transaction_route
    Authorization:
      name: Authorization
      in: header
      description: >-
        The authorization token. **This header is required if your environment
        has Access Manager enabled**.
      required: false
      schema:
        type: string
    ContentType:
      name: Content-Type
      in: header
      description: >-
        The type of media of the resource. Recommended value is
        `application/json`.
      required: false
      example: application/json
      schema:
        type: string
    XRequestId:
      name: X-Request-Id
      in: header
      description: A unique identifier used to trace and track each request.
      required: false
      example: 019c96a0-0a98-7287-9a31-786e0809c769
      schema:
        type: string
        format: uuid
  schemas:
    CreateMetadataIndexRequest:
      type: object
      description: The request body to create a metadata index.
      required:
        - metadataKey
      properties:
        metadataKey:
          type: string
          maxLength: 100
          description: >-
            The metadata key to be indexed. This key must match the metadata
            field name used in your entities.
          examples:
            - tier
        unique:
          type: boolean
          default: false
          description: >-
            Indicates whether the index enforces uniqueness. When set to `true`,
            duplicate values for this metadata key will not be allowed.
          examples:
            - false
        sparse:
          type: boolean
          default: true
          description: >-
            Indicates whether the index is sparse. When set to `true`, only
            documents containing the indexed field will be included in the
            index.
          examples:
            - true
    MetadataIndexResponse:
      type: object
      description: The response body for a metadata index.
      required:
        - indexName
        - entityName
        - metadataKey
        - unique
        - sparse
      properties:
        indexName:
          type: string
          description: The name of the index in the database.
          examples:
            - metadata.tier_1
        entityName:
          type: string
          description: The name of the entity associated with the index.
          examples:
            - transaction
        metadataKey:
          type: string
          description: The metadata key used in the index.
          examples:
            - tier
        unique:
          type: boolean
          description: Indicates whether the index enforces uniqueness.
          examples:
            - false
        sparse:
          type: boolean
          description: >-
            Indicates whether the index is sparse (ignores documents without the
            indexed field).
          examples:
            - true
    ErrorFormat:
      type: object
      description: The response message error.
      required:
        - code
        - title
        - message
      properties:
        code:
          type: string
          description: A unique, stable identifier for the error.
        title:
          type: string
          description: A brief summary of the issue.
        message:
          type: string
          description: Detailed guidance for resolving the error.
        fields:
          type: object
          additionalProperties: true
          description: Additional information about the fields that caused the error.
  examples:
    Error0009:
      summary: Missing Fields in Request
      value:
        code: '0009'
        title: Missing Fields in Request
        message: >-
          Your request is missing one or more required fields. Please refer to
          the documentation to ensure all necessary fields are included in your
          request.
        fields:
          metadataKey: metadataKey is a required field
    Error0047:
      summary: Bad Request
      value:
        code: '0047'
        title: Bad Request
        message: >-
          The server could not understand the request due to malformed syntax.
          Please check the listed fields and try again.
    Error0132:
      summary: Metadata Index Already Exists
      value:
        code: '0132'
        title: Metadata Index Already Exists
        message: >-
          A metadata index with the same key already exists for this entity.
          Please use a different key from the existing index.
    Error0134:
      summary: Invalid Metadata Key Format
      value:
        code: '0134'
        title: Invalid Metadata Key Format
        message: >-
          The metadata key format is invalid. Keys must start with a letter and
          contain only alphanumeric characters and underscores.
    Error0135:
      summary: Metadata Index Limit Exceeded
      value:
        code: '0135'
        title: Metadata Index Limit Exceeded
        message: >-
          The maximum number of metadata indexes has been reached for this
          entity. Please delete unused indexes before creating new ones.
    Error0136:
      summary: Metadata Index Creation Failed
      value:
        code: '0136'
        title: Metadata Index Creation Failed
        message: >-
          The metadata index could not be created. Please try again later or
          contact support.
    Error0138:
      summary: Invalid Entity Name
      value:
        code: '0138'
        title: Invalid Entity Name
        message: >-
          The provided entity name is not valid. Accepted values are:
          organization, ledger, asset, segment, portfolio, account, transaction,
          operation, account_type, operation_route, transaction_route.
    Error0041:
      summary: Token Missing
      value:
        code: '0041'
        title: Token Missing
        message: >-
          A valid token must be provided in the request header. Please include a
          token and try again.
    Error0042:
      summary: Invalid Token
      value:
        code: '0042'
        title: Invalid Token
        message: >-
          The provided token is expired, invalid or malformed. Please provide a
          valid token and try again.
    Error0043:
      summary: Insufficient Privileges
      value:
        code: '0043'
        title: Insufficient Privileges
        message: >-
          You do not have the necessary permissions to perform this action.
          Please contact your administrator if you believe this is an error.
    Error0046:
      summary: Internal Server Error
      value:
        code: '0046'
        title: Internal Server Error
        message: >-
          The server encountered an unexpected error. Please try again later or
          contact support.
  securitySchemes:
    bearer:
      type: http
      scheme: bearer

````