Skip to content

Date fields with ignore malformed do not ignore object and array values#143533

Merged
parkertimmins merged 7 commits intoelastic:mainfrom
parkertimmins:parker/date-ignore-malformed-object
Mar 4, 2026
Merged

Date fields with ignore malformed do not ignore object and array values#143533
parkertimmins merged 7 commits intoelastic:mainfrom
parkertimmins:parker/date-ignore-malformed-object

Conversation

@parkertimmins
Copy link
Copy Markdown
Contributor

@parkertimmins parkertimmins commented Mar 3, 2026

Date and date_nanos fields fail to index documents when the field value is an object or array, even with ignore_malformed: true. This happens because parseCreateField falls through to parser.text(), which throws an exception type not in the catch list (IllegalArgumentException | ElasticsearchParseException | DateTimeException | ArithmeticException), so the ignore_malformed handling is bypassed entirely. The fix adds an explicit check for START_OBJECT and START_ARRAY tokens before attempting to parse text. When ignore_malformed is enabled, the malformed value is skipped and the field is marked as ignored. When disabled, a clear IllegalArgumentException is thrown.

Closes #109539

Date and date_nanos fields failed to index documents containing
object or array values even when ignore_malformed was enabled.
The parser.text() call throws an exception type not caught by
the ignore_malformed handler. Handle these tokens explicitly
before attempting to parse text.

Closes elastic#109539
@parkertimmins parkertimmins self-assigned this Mar 3, 2026
@parkertimmins parkertimmins added >bug :StorageEngine/Mapping The storage related side of mappings v9.4.0 labels Mar 3, 2026
@parkertimmins parkertimmins requested a review from martijnvg March 3, 2026 21:37
@parkertimmins parkertimmins marked this pull request as ready for review March 3, 2026 21:37
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @parkertimmins, I've created a changelog YAML for you.

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

throw e;
throw new IllegalArgumentException("Cannot parse object or array as a date value");
}
} else {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really hate the indentation forced by spotless here. Unless I'm misunderstanding, this } else { and the subsequent block are indented because || context.parser().currentToken() == XContentParser.Token.START_ARRAY is indented. Looks weird to me though.

throw new IllegalArgumentException("Cannot parse object or array as a date value");
}
} else {
try {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] can you add a comment into the else clause indicating the date is being treated as a string?

// Otherwise, attempt to parse the date as if its a string

@parkertimmins parkertimmins enabled auto-merge (squash) March 4, 2026 01:34
@parkertimmins parkertimmins merged commit 5adf30e into elastic:main Mar 4, 2026
32 of 35 checks passed
burqen pushed a commit to burqen/elasticsearch that referenced this pull request Mar 5, 2026
…es (elastic#143533)

Date and date_nanos fields fail to index documents when the field value is an object or array, even with ignore_malformed: true. This happens because parseCreateField falls through to parser.text(), which throws an exception type not in the catch list (IllegalArgumentException | ElasticsearchParseException | DateTimeException | ArithmeticException), so the ignore_malformed handling is bypassed entirely. The fix adds an explicit check for START_OBJECT and START_ARRAY tokens before attempting to parse text. When ignore_malformed is enabled, the malformed value is skipped and the field is marked as ignored. When disabled, a clear IllegalArgumentException is thrown.
jfreden pushed a commit to jfreden/elasticsearch that referenced this pull request Mar 5, 2026
…es (elastic#143533)

Date and date_nanos fields fail to index documents when the field value is an object or array, even with ignore_malformed: true. This happens because parseCreateField falls through to parser.text(), which throws an exception type not in the catch list (IllegalArgumentException | ElasticsearchParseException | DateTimeException | ArithmeticException), so the ignore_malformed handling is bypassed entirely. The fix adds an explicit check for START_OBJECT and START_ARRAY tokens before attempting to parse text. When ignore_malformed is enabled, the malformed value is skipped and the field is marked as ignored. When disabled, a clear IllegalArgumentException is thrown.
spinscale pushed a commit to spinscale/elasticsearch that referenced this pull request Mar 6, 2026
…es (elastic#143533)

Date and date_nanos fields fail to index documents when the field value is an object or array, even with ignore_malformed: true. This happens because parseCreateField falls through to parser.text(), which throws an exception type not in the catch list (IllegalArgumentException | ElasticsearchParseException | DateTimeException | ArithmeticException), so the ignore_malformed handling is bypassed entirely. The fix adds an explicit check for START_OBJECT and START_ARRAY tokens before attempting to parse text. When ignore_malformed is enabled, the malformed value is skipped and the field is marked as ignored. When disabled, a clear IllegalArgumentException is thrown.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

date field types fail to index specific malformed data even with ignore_malformed enabled

3 participants