Skip to content

[BUG] Flattened Field exists Query Issue with Dotted Sub-Field Names #17069

@IAmFQQ

Description

@IAmFQQ

Describe the bug

We have encountered a discrepancy between Elasticsearch and OpenSearch when querying exists on flattened fields with dotted sub-field names.

related topic #11425

Related component

Search:Query Capabilities

To Reproduce

  1. Create an index with the following mapping:
PUT qiafan_test2
{
  "mappings": {
    "properties": {
      "earth": {
        "type": "flattened/flat_object" (ES/OS)
      }
    }
  }
}
  1. Index a document:
POST qiafan_test2/_doc/1
{
  "earth": {
    "american.north": "what an amazing day"
  }
}
  1. Run the following query:
GET qiafan_test2/_search
{
  "query": {
    "bool": {
      "boost": 1,
      "must": [
        {
          "bool": {
            "should": [
              {
                "exists": {
                  "boost": 1,
                  "field": "earth.american.north"
                }
              },
              {
                "exists": {
                  "boost": 1,
                  "field": "american.north"
                }
              }
            ]
          }
        }
      ]
    }
  }
}
 

Expected behavior

The query should return the indexed document, as the field earth.american.north exists in the document.

Observed Behavior

In Elasticsearch (7.10): The query returns the expected document.
In OpenSearch (2.18): The query does not return any results.

Additional Details

Analysis

The issue appears to be related to how OpenSearch handles exists queries on flattened fields with dotted sub-field names. Specifically:

  1. exists on earth.american.north does not behave as expected.
  2. The behavior differs from term queries, where such fields work correctly, as it supported in this PR Fix parsing of flat object fields with dots in keys #11425
  3. american.north is not supported.

Impact

We are migrating our service from Elasticsearch 7.10 to Opensearch. This behavior prevents certain queries from functioning correctly, potentially affecting applications relying on exists queries for flattened fields.

Request

We kindly request the community to investigate this issue. If this behavior is by design, clarification in the documentation would be helpful. If it is a bug, we hope for a fix or a recommended workaround.

Thank you for your assistance!

Metadata

Metadata

Assignees

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions