Elasticsearch Error: Invalid sort field - Common Causes & Fixes

No mapping found for [<field>] in order to sort on (commonly described as "Invalid sort field") is returned when a search request sorts on a field that does not exist in the target indices, has no doc_values enabled, or is a text field with no sortable subfield. The search fails with a 400. The cluster and other queries are unaffected. The fix is almost always to sort on a keyword subfield (e.g., title.keyword) rather than the analyzed text field.

What This Error Means

Sorting in Elasticsearch is backed by either doc values (default for keyword, numeric, date, boolean, geo_point fields) or fielddata (in-heap, opt-in for text fields). When you sort on a field, Elasticsearch needs a per-document scalar value. text fields are tokenized into multiple terms per document and have no single sort value, so Elasticsearch refuses to sort on them unless you explicitly enable fielddata - which is almost always the wrong choice and trips the fielddata circuit breaker.

The error also fires when the field is missing entirely from one or more indices in the wildcard pattern, or when nested fields are sorted without a nested_path.

Common Causes

  1. Sorting on a text field without a .keyword subfield. How to confirm: GET <index>/_mapping/field/<field> - if the type is text and no fields.keyword is present, sorting will fail.
  2. Typo in the field name. How to confirm: list available fields with GET <index>/_field_caps?fields=*.
  3. Field missing in some indices when searching across multiple indices. How to confirm: _field_caps shows the field exists in only a subset; add unmapped_type to the sort clause to skip indices where it is missing.
  4. doc_values explicitly disabled on the field. How to confirm: GET <index>/_mapping/field/<field> shows "doc_values": false.
  5. Nested field sorted without nested_path. How to confirm: the field's parent has type: nested in the mapping; the sort clause must include nested.path.

How to Fix Invalid Sort Field

  1. Inspect field availability across the target indices:

    GET <pattern>/_field_caps?fields=<field>
    

    The response reports per-index type and whether the field is searchable and aggregatable (a prerequisite for sorting).

  2. Sort on the keyword subfield instead of the parent text field:

    GET my-index/_search
    {
      "sort": [{ "title.keyword": "asc" }]
    }
    
  3. For text fields without a keyword subfield, add a multi-field via mapping update:

    PUT my-index/_mapping
    {
      "properties": {
        "title": {
          "type": "text",
          "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } }
        }
      }
    }
    

    New documents will populate the subfield; reindex to backfill existing data.

  4. Handle missing fields across indices:

    {
      "sort": [
        { "created_at": { "order": "desc", "unmapped_type": "date" } }
      ]
    }
    
  5. For nested fields, include nested_path:

    {
      "sort": [
        {
          "comments.posted_at": {
            "order": "desc",
            "nested": { "path": "comments" }
          }
        }
      ]
    }
    
  6. Enable doc_values on numeric/keyword fields if a mapping disabled it. This requires a reindex - doc_values is set at mapping creation:

    PUT my-index-v2
    {
      "mappings": { "properties": { "score": { "type": "long", "doc_values": true } } }
    }
    

Resolve Invalid Sort Field Automatically with Pulse

Pulse is an AI DBA for Elasticsearch and OpenSearch. When No mapping found for [<field>] in order to sort on returns a 400, Pulse:

  • Runs GET <pattern>/_field_caps?fields=<field> across the failing search's target indices, parses the per-index type and doc_values setting, inspects the mapping for a .keyword subfield, and checks for nested parents
  • Identifies which of the five causes applies: sort on a text field with no .keyword subfield, typo against _field_caps output, field missing in a subset of indices in a multi-index search, doc_values: false on the field, or a nested field used without nested_path
  • Generates the exact remediation: the sort clause rewritten to <field>.keyword, the PUT /<index>/_mapping payload adding a fields.keyword multi-field with ignore_above: 256, the unmapped_type sort parameter for sparse fields, the nested.path block, or the new-index plus reindex plan when doc_values has to change
  • Applies multi-field mapping additions with operator approval (new docs populate the subfield immediately; backfill is a reindex PR); leaves application-side query rewrites as one-click PRs

Pulse also flags dynamic_templates that omit a keyword subfield for string mappings, which is the upstream cause of most "Invalid sort field" outages in the first place.

Start a free trial to connect your cluster.

Frequently Asked Questions

Q: Why can't I sort on a text field in Elasticsearch?
A: Text fields are analyzed into multiple tokens per document, leaving no single sortable value. Enabling fielddata: true on a text field allows sorting but builds an in-heap structure that often trips the fielddata circuit breaker. Use a .keyword subfield with doc values instead.

Q: How do I sort on multiple fields in Elasticsearch?
A: Pass an array of sort clauses: "sort": [{ "status": "asc" }, { "created_at": "desc" }]. Earlier clauses take precedence; ties are broken by later clauses, then by _id.

Q: What is unmapped_type and when do I need it?
A: unmapped_type tells Elasticsearch how to treat a field that does not exist in an index targeted by the search. Without it, the request fails with "Invalid sort field" on the first index missing the field. With it (e.g., "unmapped_type": "date"), those indices are skipped.

Q: Does sorting affect Elasticsearch performance?
A: Sorting on doc-valued fields is efficient and parallelizable. Sorting on text fields with fielddata loads the in-heap structure and can trip the fielddata circuit breaker on large indices. For high-throughput sorting, prefer numeric or keyword fields with doc values.

Q: Can I sort by relevance score and a field together?
A: Yes. Use "sort": [{ "category": "asc" }, "_score"]. Documents are grouped by category, then ranked by relevance within each group.

Q: How do I sort on a runtime field?
A: Runtime fields support sorting if they emit a value of a sortable type. Define the runtime field in the search request (or in the index mapping) and reference it in the sort clause like any indexed field.

Q: What's the fastest way to diagnose "Invalid sort field" in production?
A: Pulse, the AI DBA for Elasticsearch and OpenSearch, runs _field_caps against the failing pattern, identifies whether the cause is a missing .keyword subfield, sparse mapping across indices, disabled doc_values, or a nested field needing nested_path, and proposes the correct mapping addition or query parameter (unmapped_type, nested.path). It applies the multi-field mapping update with operator approval.

Subscribe to the Pulse Newsletter

Get early access to new Pulse features, insightful blogs & exclusive events , webinars, and workshops.

We use cookies to provide an optimized user experience and understand our traffic. To learn more, read our use of cookies; otherwise, please choose 'Accept Cookies' to continue using our website.