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

# Return distinct values for a single field.

> Return the set of unique values for one document field across a collection, together with a per-value document count sorted desc. Thin wrapper over `/aggregate` for the common `SELECT DISTINCT <field>` case — use this when a UI needs a facet list (e.g. `brand_slug`) without loading every document. Null/missing values are excluded.



## OpenAPI

````yaml post /v1/collections/{collection_identifier}/documents/distinct
openapi: 3.1.0
info:
  title: Mixpeek API
  description: >-
    This is the Mixpeek API, providing access to various endpoints for data
    processing and retrieval.
  termsOfService: https://mixpeek.com/terms
  contact:
    name: Mixpeek Support
    url: https://mixpeek.com/contact
    email: info@mixpeek.com
  version: '0.82'
servers:
  - url: https://api.mixpeek.com
    description: Production
security: []
paths:
  /v1/collections/{collection_identifier}/documents/distinct:
    post:
      tags:
        - Collection Documents
      summary: Return distinct values for a single field.
      description: >-
        Return the set of unique values for one document field across a
        collection, together with a per-value document count sorted desc. Thin
        wrapper over `/aggregate` for the common `SELECT DISTINCT <field>` case
        — use this when a UI needs a facet list (e.g. `brand_slug`) without
        loading every document. Null/missing values are excluded.
      operationId: >-
        distinct_document_values_v1_collections__collection_identifier__documents_distinct_post
      parameters:
        - name: collection_identifier
          in: path
          required: true
          schema:
            type: string
            description: The unique identifier of the collection.
            title: Collection Identifier
          description: The unique identifier of the collection.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DistinctValuesRequest'
              description: Field + optional filters/limit for the distinct query.
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DistinctValuesResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    DistinctValuesRequest:
      properties:
        field:
          type: string
          title: Field
          description: >-
            Document field whose distinct values should be returned. Dotted
            paths are supported (e.g. `metadata.brand_slug`). Null/missing
            values are excluded.
          examples:
            - brand_slug
            - metadata.category
        filters:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Filters
          description: >-
            Optional pre-aggregation filters, same syntax as the standard
            aggregation endpoint. Applied before distinct values are computed.
        limit:
          anyOf:
            - type: integer
              maximum: 10000
              minimum: 1
            - type: 'null'
          title: Limit
          description: >-
            Maximum number of distinct values to return (sorted by count desc).
            Defaults to no limit on the server side; for high-cardinality fields
            always set a limit to keep the response bounded.
      type: object
      required:
        - field
      title: DistinctValuesRequest
      description: >-
        Return the set of unique values for a single field across a collection.


        Thin wrapper over the aggregation framework for the common `SELECT
        DISTINCT

        <field>` use case. Callers don't need to build a `group_by` + COUNT
        pipeline

        by hand — pass a field name and (optionally) pre-aggregation filters and

        get back a flat list of values plus per-value counts.
    DistinctValuesResponse:
      properties:
        field:
          type: string
          title: Field
          description: The field that was queried.
        values:
          items:
            $ref: '#/components/schemas/DistinctValue'
          type: array
          title: Values
          description: >-
            Distinct values sorted by descending count. Respects the `limit`
            argument; use the length of this list as the returned count.
        total_distinct:
          type: integer
          title: Total Distinct
          description: >-
            Number of distinct values in the response (== len(values)). When
            `limit` is set this can be less than the true cardinality.
      type: object
      required:
        - field
        - values
        - total_distinct
      title: DistinctValuesResponse
      description: Flat list of distinct values for a single field.
    ErrorResponse:
      properties:
        success:
          type: boolean
          title: Success
          description: Always false for error responses
          default: false
        status:
          type: integer
          title: Status
          description: HTTP status code for this error
        error:
          $ref: '#/components/schemas/ErrorDetail'
          description: Error details payload
      type: object
      required:
        - status
        - error
      title: ErrorResponse
      description: Error response model.
      examples:
        - error:
            details:
              id: ns_123
              resource: namespace
            message: Namespace not found
            type: NotFoundError
          status: 404
          success: false
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    DistinctValue:
      properties:
        value:
          title: Value
          description: The distinct field value.
        count:
          type: integer
          title: Count
          description: Number of documents with this exact value.
      type: object
      required:
        - value
        - count
      title: DistinctValue
      description: One distinct value and how many documents carry it.
    ErrorDetail:
      properties:
        message:
          type: string
          title: Message
          description: Human-readable error message
        type:
          type: string
          title: Type
          description: Stable error type identifier (machine-readable)
        code:
          anyOf:
            - type: string
            - type: 'null'
          title: Code
          description: >-
            Fine-grained error code for programmatic handling (e.g.,
            namespace_name_taken, feature_extractor_not_found). Present only
            when consumers may need to branch on a specific error condition.
        details:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Details
          description: >-
            Optional structured details to help debugging (validation errors,
            IDs, etc.)
      type: object
      required:
        - message
        - type
      title: ErrorDetail
      description: Error detail model.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````