Skip to content

[BUG] Object Field exists query returns wrong result #17808

Closed
@bugmakerrrrrr

Description

@bugmakerrrrrr

Describe the bug

Today, we skip all subfields with a prefix '_' when generating the exists query clause for the object field to avoid UOE thrown by some internal fields, like prefix field of search_as_you_type field or prefix/phrase field of text field, but this can cause unexpected behavior if a user subfield name starts with '_'. Moreover, if a object field has a derived type subfield, exists query throws a IAE.

Related component

Search

To Reproduce

A user subfield name starts with '_'

  1. create index
PUT test
{
  "mappings": {
    "properties": {
      "outer": {
        "properties": {
          "_inner": {
            "type": "keyword"
          }
        }
      }
    }
  }
}
  1. index some data
POST test/_bulk?refresh=true
{"index": {}}
{"outer": {"_inner": "foo"}}
  1. exists query
POST test/_search
{
  "query": {
    "exists": {
      "field": "outer"
    }
  }
}

which matches no docs

A object field has a derived type subfield

  1. create index
PUT test
{
  "mappings": {
    "properties": {
      "log": {
        "properties": {
          "request": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword"
              }
            }
          }
        }
      }
    },
    "derived": {
      "log.timestamp": {
        "type": "date",
        "format": "MM/dd/yyyy",
        "script": {
          "source": "emit(Long.parseLong(doc[\"log.request.keyword\"].value.splitOnToken(\" \")[0]))"
        }
      }
    }
  }
}
  1. index some data
POST test/_bulk?refresh=true
{"index": {}}
{"log": {"request": "894030400 GET /english/images/france98_venues.gif HTTP/1.0 200 778"}}
  1. exists query
POST test/_search
{
  "query": {
    "exists": {
      "field": "log"
    }
  }
}

which throws a IAE

"failed_shards": [
      {
        "shard": 0,
        "index": "test",
        "node": "5vtqUIDFSVuf1iPbEJ7Qig",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: Field [log.timestamp] of type [derived] does not support exist queries",
          "index": "test",
          "index_uuid": "oR_xg-kuTE-G_KWZX6Q0ZQ",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "Field [log.timestamp] of type [derived] does not support exist queries"
          }
        }
      }
    ]

Expected behavior

The exists query should match all docs.

Additional Details

No response

Metadata

Metadata

Labels

SearchSearch query, autocomplete ...etcbugSomething isn't workingv3.0.0Issues and PRs related to version 3.0.0

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions