Closed
Description
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 '_'
- create index
PUT test
{
"mappings": {
"properties": {
"outer": {
"properties": {
"_inner": {
"type": "keyword"
}
}
}
}
}
}
- index some data
POST test/_bulk?refresh=true
{"index": {}}
{"outer": {"_inner": "foo"}}
- exists query
POST test/_search
{
"query": {
"exists": {
"field": "outer"
}
}
}
which matches no docs
A object field has a derived type subfield
- 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]))"
}
}
}
}
}
- index some data
POST test/_bulk?refresh=true
{"index": {}}
{"log": {"request": "894030400 GET /english/images/france98_venues.gif HTTP/1.0 200 778"}}
- 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
Assignees
Labels
Type
Projects
Status
✅ Done