Skip to content

[BUG] field name with dot is missing in output without fields command #3477

Closed

Description

@LantaoJin

What is the bug?
field name with dot (such as test.occupation) is missing in query output without fields command

How can one reproduce the bug?

PUT /ltjin-test1
{
  "mappings": {
    "properties": {
      "name": {
        "type": "keyword"
      },
      "test.occupation": {
        "type": "text"
      },
      "country": {
        "type": "text"
      },
      "salary": {
        "type": "integer"
      },
      "year": {
        "type": "integer"
      },
      "month": {
        "type": "integer"
      }
    }
  }
}
POST _bulk
{"index":{"_index" : "ltjin-test1","_id":"1"}}
{"name":"Jake","test.occupation":"Engineer","country":"England","salary":100000,"year":2023,"month":4}

the test.occupation field is missing in following query.

POST /_plugins/_ppl
{
  "query" : """
  source = ltjin-test1
  """
}

but we can output it by following query.

POST /_plugins/_ppl
{
  "query" : """
  source = ltjin-test1 | fields test.occupation
  """
}

What is the expected behavior?
the test.occupation field should output in query

POST /_plugins/_ppl
{
  "query" : """
  source = ltjin-test1
  """
}

should

What is your host/environment?

  • Version 2.19

Activity

  1. added
    bug
    and removed on Mar 25, 2025
  2. changed the title [-][BUG] field name with `dot` is missing without `fields` command[/-] [+][BUG] field name with `dot` is missing in output without `fields` command[/+] on Mar 25, 2025
  3. added
    PPL
    and removed on Mar 25, 2025
  4. qianheng-aws commented on Mar 25, 2025

    @qianheng-aws
    Collaborator

    It seems to be a bug(/feature?) of OpenSearch DSL instead of PPL.

    The root cause is the document you put into this index mismatches its mapping.

    In the mapping of index, test.occupation is a nested field of test while it is viewed as a root field in the document.

    GET /ltjin-test1/_mapping
    {
      "ltjin-test1": {
        "mappings": {
          "properties": {
            "country": {
              "type": "text"
            },
            "month": {
              "type": "integer"
            },
            "name": {
              "type": "keyword"
            },
            "salary": {
              "type": "integer"
            },
            "test": {
              "properties": {
                "occupation": {
                  "type": "text"
                }
              }
            },
            "year": {
              "type": "integer"
            }
          }
        }
      }
    }
    

    The correct document content should be:

    POST _bulk
    {"index":{"_index" : "ltjin-test1","_id":"1"}}
    {"name":"Jake","test": {"occupation": "Engineer"},"country":"England","salary":100000,"year":2023,"month":4}
    
  5. LantaoJin commented on Mar 25, 2025

    @LantaoJin
    MemberAuthor

    The correct document content should be:

    POST _bulk
    {"index":{"_index" : "ltjin-test1","_id":"1"}}
    {"name":"Jake","test": {"occupation": "Engineer"},"country":"England","salary":100000,"year":2023,"month":4}
    

    Ah, I see. Thanks @qianheng-aws . Close this.

  6. penghuo commented on Mar 25, 2025

    @penghuo
    Collaborator

    @LantaoJin @qianheng-aws

    IMO, For PPL, ths issue is index mapping not match indexed source doc, then we can not parsed source data correcttly
    field type

    {"test": Struct("occupation": string)}
    

    but data stored is

    "test.occupation": "Engineer"
    

    OpenSearch can read it correctlly actually.

    GET {{baseUrl}}/ltjin-test1/_search
    Content-Type: application/x-ndjson
    
    {
      "fields": [
        "test.occupation"
      ]
    }
    
  7. qianheng-aws commented on Mar 26, 2025

    @qianheng-aws
    Collaborator

    Then I think it need to be supported from the core. It's required that mapping should support field name with dot, and when adding a document with such a field it should update mapping as well.

  8. reopened this on Apr 8, 2025
  9. penghuo commented on Apr 9, 2025

    @penghuo
    Collaborator

    Problems

    • With following test data.
    ###
    POST {{baseUrl}}/logs-ppl-test-3/_doc
    Content-Type: application/x-ndjson
    
    {
        "log.json": {
            "requestTime": "0.001",
            "status": "404"
        }
    }
    
    • OpenSearch DSL support read data with full json path
    ###
    GET {{baseUrl}}/logs-ppl-test-3/_search
    Content-Type: application/x-ndjson
    
    {
        "fields": [
            "log.json.status"
        ],
        "_source": false
    }
    
    ### Response
      "hits": [
        {
          "_index": "logs-ppl-test-3",
          "_id": "YbU7HJYBgDwE50urGBwA",
          "_score": 1.0,
          "fields": {
            "log.json.status": [
              "404"
            ]
          }
        }
      ]
    
    • PPL does not support read data with full json path
    ###
    POST {{baseUrl}}/_plugins/_ppl
    Content-Type: application/x-ndjson
    
    {
        "query": "source=logs-ppl-test-3 | fields log.json"
    }
    
    ### Response
    {
      "schema": [
        {
          "name": "log.json.status",
          "type": "string"
        }
      ],
      "datarows": [
        [
          null
        ]
      ],
      "total": 1,
      "size": 1
    }
    
    • OpenSearch DSL and PPL does not support read data with partial json path
    ###
    POST {{baseUrl}}/_plugins/_ppl
    Content-Type: application/x-ndjson
    
    {
        "query": "source=logs-ppl-test-3 | fields log"
    }
    
    {
      "schema": [
        {
          "name": "log",
          "type": "struct"
        }
      ],
      "datarows": [
        [
          null
        ]
      ],
      "total": 1,
      "size": 1
    }
    
    ###
    GET {{baseUrl}}/logs-ppl-test-3/_search
    Content-Type: application/x-ndjson
    
    {
        "fields": [
            "log"
        ],
        "_source": false
    }
    
    ### Response
        "hits": [
          {
            "_index": "logs-ppl-test-3",
            "_id": "YbU7HJYBgDwE50urGBwA",
            "_score": 1.0
          }
        ]
    

    Proposal

    • By default, ignore populate Object type field into Schema, only populate full json path. for instance, the index mapping of logs-ppl-test-3 is
    {
      "properties": {
        "log": {
          "properties": {
            "json": {
              "properties": {
                "requestTime": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                },
                "status": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    

    currently, index schema is

    [
      {
        "name": "log"
        "type": "struct"
      }
    ]
    

    we could populate inner field instead

    [
      {
        "name": "log.json.requestTime"
        "type": "string"
      },
      {
        "name": "log.json.status"
        "type": "string"
      }
    ]
    
    • User could enforce populate object type fields as Struct data type by setting/metadata. Then, it required mapping exactally match _source data.
  10. anasalkouz commented on Apr 15, 2025

    @anasalkouz
    Member

    @LantaoJin @penghuo is this issue on track? is this will be fixed on 3.0?

  11. dai-chen commented on Apr 16, 2025

    @dai-chen
    Collaborator

    Root Cause

    The current symbol resolution logic in ReferenceExpression attempts to resolve a nested field path (e.g., log.json.status) by recursively splitting the path and looking for child values in ExprValue map. It does not support the case where intermediate field names contain dots (e.g., "address.local" as a single field name). As a result, the resolution ends up with missing value because the logic expects "log" → "json" → "status", not "log.json" → "status".

    Code reference: ReferenceExpression.java#L103

    🔸 Note: This issue is also present in the V3 engine, which shares the same recursive resolution logic. Code reference: OpenSearchIndexEnumerator

    Solutions

    🔹 Solution 1: Read from _source using recursive prefix matching

    • Implement logic similar to SourceLookup.extractValue() in OpenSearch core:
      • At each recursion step, attempt to join increasingly longer prefixes of the path (e.g., "log", "log.json", etc.) and match them against keys in the ExprValue map.
      • Code reference:
        XContentMapValues.java#L187
    • Pros: Quick and compatible fix.
    • Cons: May introduce performance overhead due to repeated prefix enumeration and lookups at each level.

    🔹 Solution 2: Read from _source into a flat map of full paths

    • When reading _source into ExprValue, flatten it into a map where each key is a full field path (e.g., "log.json.status") and resolve symbols by exact match.
    • Pros: Simple and efficient symbol resolution logic.
    • Cons: Only works for leaf value access (e.g., cannot access log.json as an object).

    🔹 Solution 3: Read from doc_values instead of _source

    • Modify ExprValue factory to read directly from doc_values
    • Pros: Avoids dependency on _source; provides faster access for many use cases.
    • Cons: May have performance implications if too many fields are involved; not all field types (e.g., text, object) support doc_values.

    Issues Related

    Inconsistency between Describe Statement and Select * Expansion

    The DESCRIBE command flattens all fields in the index mapping, including all prefixes for dotted field name:

    POST localhost:9200/sample_data/_doc
    {
       "name": "bob smith",
       "project.year": 1990,
       "address": {
         "state": "WA",
         "city": "seattle",
         "project.year": 1990
       },
       "address.local": {
         "state": "WA"
       }
     }
    
    {
      "query": "describe sample_data | fields COLUMN_NAME"
    }
    {
      "schema": [
        {
          "name": "COLUMN_NAME",
          "type": "string"
        }
      ],
      "datarows": [
        [
          "name"
        ],
        [
          "project"
        ],
        [
          "project.year"
        ],
        [
          "address"
        ],
        [
          "address.city"
        ],
        [
          "address.local"
        ],
        [
          "address.local.state"
        ],
        [
          "address.project"
        ],
        [
          "address.project.year"
        ],
        [
          "address.state"
        ]
      ],
      "total": 10,
      "size": 10
    }
    

    The SELECT * expansion only retrieves top-level field name from the symbol table:

    {
      "query": "source = sample_data"
    }
    {
      "schema": [
        {
          "name": "name",
          "type": "string"
        },
        {
          "name": "project",
          "type": "struct"
        },
        {
          "name": "address",
          "type": "struct"
        }
      ],
      "datarows": [
        [
          "bob smith",
          null,
          {
            "project.year": 1990,
            "city": "seattle",
            "state": "WA"
          }
        ]
      ],
      "total": 1,
      "size": 1
    }
    
  12. LantaoJin commented on Apr 17, 2025

    @LantaoJin
    MemberAuthor

    Let me re-describe the issue:
    User can ingest docs with different ways.
    Approach 1

    PUT ltjin-test1/_doc/106
    {
        "log.json": {
            "requestTime": "0.001",
            "status": "404"
        }
    }
    

    Approach 2

    PUT ltjin-test1/_doc/107
    {
      "log": {
        "json": {
          "requestTime": "0.002",
          "status": "200"
        }
      }
    }
    

    The mappings are same whatever by Approach 1 or Approach 2

    {
      "ltjin-test1": {
        "mappings": {
          "properties": {
            "log": {
              "properties": {
                "json": {
                  "properties": {
                    "requestTime": {
                      "type": "text",
                      "fields": {
                        "keyword": {
                          "type": "keyword",
                          "ignore_above": 256
                        }
                      }
                    },
                    "status": {
                      "type": "text",
                      "fields": {
                        "keyword": {
                          "type": "keyword",
                          "ignore_above": 256
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    

    The difference is that the docs have different _source

    GET /ltjin-test1/_search
    {
        "fields": [
            "log.json.status"
        ]
    }
    
        "hits": [
          {
            "_index": "ltjin-test1",
            "_id": "107",
            "_score": 1,
            "_source": {
              "log": {
                "json": {
                  "requestTime": "0.002",
                  "status": "200"
                }
              }
            },
            "fields": {
              "log.json.status": [
                "200"
              ]
            }
          },
          {
            "_index": "ltjin-test1",
            "_id": "106",
            "_score": 1,
            "_source": {
              "log.json": {
                "requestTime": "0.001",
                "status": "404"
              }
            },
            "fields": {
              "log.json.status": [
                "404"
              ]
            }
          }
        ]
    

    PPL results with full path, root path and partial path are all correct for the doc created by Approach 1. But incorrect by Approach 2.

    POST /_plugins/_ppl
    {
      "query" : """
      source = ltjin-test1 | fields log.json.status
      """
    }
    

    Returns

    {
      "schema": [
        {
          "name": "log.json.status",
          "type": "string"    <---- correct for both
        }
      ],
      "datarows": [
        [
          "200"     <---- correct
        ],
        [
          null      <---- incorrect
        ]
      ],
      "total": 2,
      "size": 2
    }
    
    POST /_plugins/_ppl
    {
      "query" : """
      source = ltjin-test1 | fields log
      """
    }
    

    Returns

    {
      "schema": [
        {
          "name": "log",
          "type": "struct"  <---- correct for Approach 1 but incorrect for Approach 2
        }
      ],
      "datarows": [
        [
          {
            "json": {
              "requestTime": "0.002",
              "status": "200"
            }     <---- correct
          }
        ],
        [
          null    <---- incorrect
        ]
      ],
      "total": 2,
      "size": 2
    }
    
    POST /_plugins/_ppl
    {
      "query" : """
      source = ltjin-test1 | fields log.json
      """
    }
    

    Returns

    {
      "schema": [
        {
          "name": "log.json",
          "type": "struct"    <---- correct for both
        }
      ],
      "datarows": [
        [
          {
            "requestTime": "0.002",
            "status": "200"
          }     <---- correct
        ],
        [
          {
            "requestTime": "0.001",
            "status": "404"
          }     <---- correct
        ]
      ],
      "total": 2,
      "size": 2
    }
    

    The issue happens when users treat the nested/struct object in log.json level instead of root level (log) in data ingestion?

  13. dai-chen commented on Apr 17, 2025

    @dai-chen
    Collaborator

    @LantaoJin Thanks for the additional context! I've updated my comment here. My current testing shows that both V2 and V3 engines exhibit the same issue.

    I think the main issue described is just one part of a broader problem. We need a comprehensive design to ensure consistent behavior when handling object fields in our core engine — including Describe index, SELECT *, SELECT with specific fields etc — considering the user experience in OpenSearch Dashboards and BI tool integrations (via SQL). cc: @penghuo @anasalkouz

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

    PPLPriority-Highbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions