Skip to content

[BUG] sort on a text field with dedup or a computed key returns 400 "Text fields are not optimised for sorting" #6020

Backlog

Description

@Swiddis

What is the bug?
sort t on a text field works on its own, but sort t | dedup s and eval e = abs(n) | sort t, e push the text sort down to OpenSearch, and the shard rejects it.

How can one reproduce the bug?

  1. Create the index and doc
curl -s -X PUT localhost:9200/hdemo -H 'Content-Type: application/json' \
  -d '{"mappings":{"properties":{"s":{"type":"keyword"},"t":{"type":"text"},"n":{"type":"integer"},"d":{"type":"double"},"b":{"type":"boolean"},"ts":{"type":"date"}}}}' | jq .acknowledged
curl -s -X POST 'localhost:9200/hdemo/_doc?refresh=true' -H 'Content-Type: application/json' \
  -d '{"s":"abc","t":"hello world","n":7,"d":1.5,"b":true,"ts":"2026-01-02T03:04:05Z"}' | jq .result
  1. A text sort followed by dedup:
curl -s -X POST localhost:9200/_plugins/_ppl -H 'Content-Type: application/json' \
  -d '{"query":"source=hdemo | sort t | dedup s"}' | jq -c '{status, error: .error.details[0:90]}'
# {"status":400,"error":"java.sql.SQLException: exception while executing query: Failed to fetch data from the inde"}
  1. A text sort with a function-computed key:
curl -s -X POST localhost:9200/_plugins/_ppl -H 'Content-Type: application/json' \
  -d '{"query":"source=hdemo | eval e = abs(n) | sort t, e"}' | jq -c '{status, error: .error.details[0:90]}'
# {"status":400,"error":"java.sql.SQLException: exception while executing query: Failed to fetch data from the inde"}
  1. Both queries return rows with plugins.calcite.pushdown.enabled=false, and sort t | head 1 | fields t returns [["hello world"]] with pushdown on.

What is the expected behavior?
The same rows as with pushdown off. Either the sort stays in memory, as it does for sort t alone, or it uses a keyword sub-field when one exists.

What is your host/environment?

Do you have any screenshots?
N/A

Do you have any additional context?

  • The inner shard error is Text fields are not optimised for operations that require per-document field data like aggregations and sorting....
  • Step 2 goes through dedup pushdown (top_hits/composite carrying the sort). Step 3 happens only with a function key (abs(n), floor(d), but not n + 1), which pushes both keys as one script/field sort. Splitting the sort (sort e | sort t) avoids it (not verified which rule pushes the text key).
  • Also seen: sort -t, -ts | dedup t, ts.
  • Found by a property-based type checker (hegel).

Activity

  1. added
    bug
    PPL
    dynamic-test
    and removed on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    PPLbugdynamic-test

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions