Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RequestResponseSerializer.Deserialize cannot deserialize "preserve_original" : "true" #7755

Closed
gobaaspudden opened this issue Jun 19, 2023 · 2 comments · Fixed by #7839
Closed
Labels
8.x Relates to 8.x client version

Comments

@gobaaspudden
Copy link

Elastic.Clients.Elasticsearch version: 8.1.1

Elasticsearch version: 8.7.1

.NET runtime version: 4.8

Operating system version: Windows 11

Description of the problem including expected versus actual behavior:
There is a missmatch between elasticsearch json and the client deserializer when creating an index with
settings - analysis - filter - custom_ascii_folding - preserve_original : true
Expected behavior: Add index and read index without error.
Actual behavior: Reading index will result in json parse exception

Steps to reproduce:

  1. Add index with filter tokenfilter tf -> tf.AsciiFolding("custom_ascii_folding", e => e.PreserveOriginal(true));
  2. Get Index - Indices.Get(new GetIndexRequest(Indices.All))
  3. Exception occurs

Expected behavior
Elastic should serialize PreserveOriginal as bool ( "preserve_original": true )
or RequestResponseSerializer should be able to handle conversion from string "true" to bool.

Provide DebugInformation (if relevant):

Here is the GetIndex response from elastic 8.7.1:
{"article-test-en-us":{"aliases":{},"mappings":{"properties":{"categories":{"type":"keyword"},"content":{"type":"text","index_options":"offsets","analyzer":"custom_html"},"defaultViewOriginContexts":{"type":"keyword"},"statistics":{"type":"nested","properties":{"popularity":{"type":"double"},"role":{"type":"keyword"},"viewOriginContext":{"type":"keyword"}}},"title":{"type":"text","index_options":"offsets","analyzer":"custom_html"}}},"settings":{"index":{"routing":{"allocation":{"include":{"_tier_preference":"data_content"}}},"number_of_shards":"1","provided_name":"article-test-en-us","creation_date":"1687162213728","analysis":**_{"filter":{"custom_ascii_folding":{"type":"asciifolding","preserve_original":"true"},_**"english_stemmer":{"type":"stemmer","language":"english"},"english_stop":{"type":"stop","stopwords":"_english_"}},"analyzer":{"custom_html":{"filter":["lowercase","custom_ascii_folding","english_stop","english_stemmer"],"char_filter":["custom_html_strip"],"type":"custom","tokenizer":"standard"}},"char_filter":{"custom_html_strip":{"type":"html_strip"}}},"number_of_replicas":"1","uuid":"Zzyhj9S9QfeLBgozuC0H3A","version":{"created":"8070199"}}}}}

RequestResponseSerializer.Deserialize()

System.Text.Json.JsonException: The JSON value could not be converted to System.Nullable1[System.Boolean]. Path: $.preserve_original | LineNumber: 2 | BytePositionInLine: 42. ---> System.InvalidOperationException: Cannot get the value of a token type 'String' as a boolean.`

Stack Trace: 
ThrowHelper.ThrowInvalidOperationException_ExpectedBoolean(JsonTokenType tokenType)
Utf8JsonReader.GetBoolean()
BooleanConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
NullableConverter1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) JsonPropertyInfo1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
ObjectDefaultConverter1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) --- End of inner exception stack trace --- ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex) <35 more frames...> JsonSerializer.Deserialize[TValue](Utf8JsonReader& reader, JsonSerializerOptions options) ResolvableDictionaryResponseConverterInner3.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) line 74
JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
JsonSerializer.ReadCore[TValue](Utf8JsonReader& reader, JsonTypeInfo jsonTypeInfo, ReadStack& state)
JsonSerializer.ContinueDeserialize[TValue](ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack, JsonTypeInfo jsonTypeInfo)
JsonSerializer.ReadFromStream[TValue](Stream utf8Json, JsonTypeInfo jsonTypeInfo)
JsonSerializer.Deserialize[TValue](Stream utf8Json, JsonSerializerOptions options)

@gobaaspudden gobaaspudden added the 8.x Relates to 8.x client version label Jun 19, 2023
@gobaaspudden
Copy link
Author

I discovered the same issue for settings - index- lifecycle - "indexing_complete" : "true"

@stevejgordon
Copy link
Contributor

This looks like a spec issue which needs to be addressed to support these properties potentially being returned as strings rather than raw boolean values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to 8.x client version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants