[Connector API] Don't index literal nulls to connector doc #110543
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
As part of elastic/elasticsearch-specification#2675, we realized that when creating a connector, all properties are written to the index, even if they have a null value. This creates inconsistency between what can be optional and what is actually nullable (semantic-null). We don't need to store literal nulls in the connector index; it's fine to treat connector properties as optionals.
Previously, null values were written to the index to match the status quo (where every single property was preset to null), but this is unnecessary.
This PR ensures that properties are only written to the index upon connector creation if the field is non-null. As a result, fields like last_seen or sync_cursor won't be written to the index and won't be present in the response if they are null. This changes the current behavior where these fields are set to null.
I've tested this change with Kibana, Connector APIs, and the connector service, and everything is working fine. Additionally, this fix will resolve failing client tests due to properties that contain null values.
Code references
The logic to create connector is in the ConnectorIndexService, see createConnector method. This initialises
Connector
object with user-provided args and presets other properties to default values. There are a number of undefined properties (likelast_seen
,sync_cursor
, etc).This logic uses Connector's toXContent method to write "JSON" to index. The changes to
toXContent
from this PR ensure that we don't writenulls
to index.