opensearch-project/OpenSearch

[BUG] Exists query fails if object has "search_as_you_type" field

Open

#11,821 opened on Jan 9, 2024

View on GitHub
 (8 comments) (0 reactions) (1 assignee)Java (1,505 forks)batch import
Searchbuggood first issue

Repository metrics

Stars
 (8,123 stars)
PR merge metrics
 (Avg merge 5d 9h) (266 merged PRs in 30d)

Description

Describe the bug

The "exists" query on an object field will fail when a "search_as_you_type" field is nested under that object. See step to reproduce for an example.

Related component

Search

To Reproduce

Queries:

PUT bug_exists
{
  "mappings": {
    "properties": {
      "user": {
        "properties": {
          "name": {
            "type": "keyword",
            "normalizer": "lowercase",
            "fields": {
              "lookup": {
                "type": "search_as_you_type",
                "doc_values": false,
                "max_shingle_size": 3
              }
            }
          }
        }
      }
    }
  }
}

POST bug_exists/_doc
{
  "user": {
    "name": "foo"
  }
}

POST bug_exists/_search
{
  "query": {
    "exists": {
      "field": "user"
    }
  }
}

Executing search query gives the following error:

{
  "error": {
    "root_cause": [
      {
        "type": "unsupported_operation_exception",
        "reason": "unsupported_operation_exception: null"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "bug_exists",
        "node": "vQR3k_EpTqGwm-tWhNHpJA",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: null",
          "index": "bug_exists",
          "index_uuid": "2XEpnkKbSL62szsFvLvOtw",
          "caused_by": {
            "type": "unsupported_operation_exception",
            "reason": "unsupported_operation_exception: null"
          }
        }
      }
    ],
    "caused_by": {
      "type": "unsupported_operation_exception",
      "reason": "unsupported_operation_exception: null"
    }
  },
  "status": 400
}

Expected behavior

The following query should not fail and return the document

POST bug_exists/_search
{
  "query": {
    "exists": {
      "field": "user"
    }
  }
}

Additional Details

Host/Environment (please complete the following information):

  • AWS OpenSearch 2.11

Additional context The same bug in ElasticSearch fixed in 8.0 https://github.com/elastic/elasticsearch/issues/64609

Contributor guide