Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[BUG] exists queries on nested flat_object fields throw a string_index_out_of_bounds_exception #16795

Open
chamidiz opened this issue Dec 6, 2024 · 2 comments · May be fixed by #16803
Open
Labels
bug Something isn't working Search Search query, autocomplete ...etc

Comments

@chamidiz
Copy link

chamidiz commented Dec 6, 2024

Describe the bug

When creating an index mapping with an object field that has a subfield of flat_object exists queries or query strings with <field>:* throw a string_index_out_of_bounds_exception.

Related component

Search

To Reproduce

Create an index with a mapping with a flat_object subfield to an object:

PUT flat-object-test
{
    "mappings": {
        "properties": {
            "foo": {
                "properties": {
                    "bar": {
                        "type": "keyword"
                    },
                    "baz": {
                        "type": "flat_object"
                    }
                }
            }
        }
    }
}

Create a document to search:

POST flat-object-test/_doc
{
    "foo": {
        "bar": "abcdef",
        "baz": {
            "a": "b"
        }
    }
}

Search with an exists query:

GET flat-object-test/_search
{
    "query": {
        "exists": {
            "field": "foo"
        }
    }
}

Result is an exception:

{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: Index 8 out of bounds for length 8",
        "index": "flat-object-test",
        "index_uuid": "vyS6P9-jTdKcETemZjlr7Q"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "flat-object-test",
        "node": "ehTrfc9eT26MNpzRtJiPYQ",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: Index 8 out of bounds for length 8",
          "index": "flat-object-test",
          "index_uuid": "vyS6P9-jTdKcETemZjlr7Q",
          "caused_by": {
            "type": "string_index_out_of_bounds_exception",
            "reason": "Index 8 out of bounds for length 8"
          }
        }
      }
    ]
  },
  "status": 400
}

NOTE: exists query on foo.bar or foo.baz operate as expected. Only affected for the top-level field.

Expected behavior

Searching for _exists_: foo should not throw an exception.

Additional Details

Tested on Opensearch versions 2.15.0 and 2.18.0

@chamidiz chamidiz added bug Something isn't working untriaged labels Dec 6, 2024
@github-actions github-actions bot added the Search Search query, autocomplete ...etc label Dec 6, 2024
@kkewwei
Copy link
Contributor

kkewwei commented Dec 6, 2024

It's imported by DynamicKeyFieldTypeLookup, when iterating through all fields, the DynamicKeyFieldTypeLookup imports a dynamic field named "foo. baz.", which casues the exception.

@chamidiz, do you mind if I pick this up and fix it?

@chamidiz
Copy link
Author

chamidiz commented Dec 6, 2024

It's imported by DynamicKeyFieldTypeLookup, when iterating through all fields, the DynamicKeyFieldTypeLookup imports a dynamic field named "foo. baz.", which casues the exception.

@chamidiz, do you mind if I pick this up and fix it?

Absolutely, thank you for looking!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Search Search query, autocomplete ...etc
Projects
Status: 🆕 New
Development

Successfully merging a pull request may close this issue.

3 participants