Skip to content

[BUG] Nested Function With Sort Doesn't Sort Inner Hits #1788

Closed as not planned

Description

@forestmvey

What is the bug?
Sorting on nested fields does not sort inner_hits of response.

Dataset:

{"index":{"_id":"1"}}
{"message":[{"info":"c"},{"info":"a"}]}
{"index":{"_id":"2"}}
{"message":{"info":"d"}}

Mapping:

{
  "mappings": {
    "properties": {
      "message": {
        "type": "nested",
        "properties": {
          "info": {
            "type": "keyword",
            "index": "true"
          }
        }
      }
    }
  }
}

Query:

SELECT nested(message.info) FROM nested_objects ORDER BY nested(message.info) DESC;

Response:

{
    "schema": [
        {
            "name": "message.info",
            "type": "keyword"
        }
    ],
    "total": 3,
    "datarows": [
        [
            "d"
        ],
        [
            "c"
        ],
        [
            "a"
        ]
    ],
    "size": 3,
    "status": 200
}

How can one reproduce the bug?
Steps to reproduce the behavior:

  1. Upload dataset with index mapping.
  2. Run SQL query.
  3. Verify Results.

What is the expected behavior?
The hits portion of the response is sorted, and the inner_hits portion is not sorted. The inner_hits could be sorted, but this would be two separate sorts and all returned data would not be one contiguous sort. Perhaps an in-memory solution may be the only fix here.

What is your host/environment?

  • OS: IOS
  • Version: 13.4.1
  • Plugins: SQL

Do you have any screenshots?
N/A

Do you have any additional context?
Legacy engine bug.

Activity

  1. added
    bug
    legacy
    on Jun 27, 2023
  2. Yury-Fridlyand commented on Jun 27, 2023

    @Yury-Fridlyand
    Collaborator

    Probably, we shouldn't push down sort if nested is present. This is similar to #1764. Could be done after optimizer rework described in #1752 .

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

    buglegacy

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions