Skip to content

[Feature Request] [BUG] _source include / exclude validation #20612

@urmichm

Description

@urmichm

Is your feature request related to a problem? Please describe

include/exclude contradiction

I’m not sure whether this is a bug or expected behavior, but a query with both _source.includes and _source.excludes is accepted even when includes contradicts excludes.

Example:

GET /people-index/_search
{
  "_source" : {
    "excludes": ["name"],
    "includes": ["name", "age"]
  },
  "query" : {
    // my wonderful query
  },
  "size" : 20,
  "sort" : [ {
    "_score" : { "order" : "desc" }
  } ]
}

Result: hits contain only age. That is somewhat logical, but arguably providing includes and excludes together should not be allowed. (especially when they contradict one another ⛔ )

Empty arrays behavior

If excludes is an empty array, then all fields are returned. Looks logical.
"_source": { "excludes": [] }, means nothing excluded. 👌

If includes is an empty array, then all fields are still returned. This looks like a bug. ⚠️⚠️⚠️
If no fields are included, no fields shall be returned.

"_source": { "includes": [] } means an empty _source object -> "_source": {} but it isn't ⚠️

Describe the solution you'd like

I am not expecting no _source as if i had provided "_source": false in the query ,
but i would expect an empty _source object.

An empty source object and a null source object are different.

As a work around, we could start with "includes": [ "" ], rather then an empty array, and then add the fields we need. If no fields are added, the source objects will be empty.

However, starting with a non-empty array to represent the semantics of an empty one... well, it is confusing. 😕

Example:

GET /people-index/_search
{
  "_source": {
    "includes": [ "" ]
  }, 
  "query" : { /* the best query */ }
}

Results in following hits:

"hits": [
      {
        "_index": "people-index",
        "_id": "111111",
        "_score": 1.7178972,
        "_source": {}
      },
      {
        "_index": "people-index",
        "_id": "222222",
        "_score": 1.7136133,
        "_source": {}
      },

Since the empty fields are not allowed, no field named "" exist and therefore the resulting source is empty.

Related component

Search:Query Insights

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions