Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] rename does not work with struct field #3279

Open
currantw opened this issue Jan 30, 2025 · 1 comment
Open

[BUG] rename does not work with struct field #3279

currantw opened this issue Jan 30, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@currantw
Copy link
Contributor

currantw commented Jan 30, 2025

What is the bug?

The rename command returns incorrect results when applied to a struct field.

While the renamed field is correctly added to the search results, additional fields are also added that correspond to each of the fields within the struct, and which contain null values.

Consider the following input data:

name location
Seattle { country: 'United States' }
Vancouver { country: 'Canada' }

Query: source=input | rename location as renamed_location

Expected Results:

name renamed_location
Seattle { country: 'United States' }
Vancouver { country: 'Canada' }

Actual Results:

name country renamed_location
Seattle null { country: 'United States' }
Vancouver null { country: 'Canada' }

How can one reproduce the bug?

See comment below for sample mapping, input data, query, and results.

What is the expected behaviour?

See above. Struct field should be renamed, not additional columns should be created.

What is your host/environment?

Not applicable.

Do you have any screenshots?

Not applicable. See example above and sample mapping, input data, query, and results in comment below.

Do you have any additional context?

Discovered during work on #3030.

@currantw currantw added bug Something isn't working untriaged labels Jan 30, 2025
@currantw
Copy link
Contributor Author

EXAMPLE

Mapping:

{
  "mappings": {
    "properties": {
      "name": {
        "type": "keyword"
      },
      "location": {
        "type": "object",
        "properties": {
          "state": {
            "type": "keyword"
          },
          "province": {
            "type": "keyword"
          },
          "country": {
            "type": "keyword"
          },
          "coordinates": {
            "type": "object",
            "properties": {
              "latitude": {
                "type": "double"
              },
              "longitude": {
                "type": "double"
              }
            }
          }
        }
      }
    }
  }
}

Data (Bulk):

{"index":{"_id":"1"}}
{"name": "Seattle", "location": { "state": "Washington", "country": "United States", "coordinates": {"latitude": 47.6061, "longitude": -122.3328}}}
{"index":{"_id":"2"}}
{"name": "Vancouver", "location": { "province": "British Columbia", "country": "Canada", "coordinates": {"latitude": 49.2827, "longitude": -123.1207}}}

Query:

source=cities | rename location AS renamed_location

Response:

{
    "schema": [
        {
            "name": "name",
            "type": "string"
        },
        {
            "name": "location.coordinates",
            "type": "struct"
        },
        {
            "name": "location.country",
            "type": "string"
        },
        {
            "name": "location.province",
            "type": "string"
        },
        {
            "name": "location.state",
            "type": "string"
        },
        {
            "name": "renamed_location",
            "type": "struct"
        }
    ],
    "datarows": [
        [
            "Seattle",
            null,
            null,
            null,
            null,
            {
                "state": "Washington",
                "country": "United States",
                "coordinates": {
                    "latitude": 47.6061,
                    "longitude": -122.3328
                }
            }
        ],
        [
            "Vancouver",
            null,
            null,
            null,
            null,
            {
                "province": "British Columbia",
                "country": "Canada",
                "coordinates": {
                    "latitude": 49.2827,
                    "longitude": -123.1207
                }
            }
        ]
    ],
    "total": 2,
    "size": 2

@currantw currantw changed the title [BUG] Command rename does not work withstruct field [BUG] Command rename does not work with struct field Jan 30, 2025
@currantw currantw changed the title [BUG] Command rename does not work with struct field [BUG] rename does not work with struct field Feb 5, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants