Expected JSON 'StartObject' token, but got 'String'.
Closed this issue · 2 comments
Elastic.Clients.Elasticsearch version: 8.19.6
Elasticsearch version: 8.18.4
.NET runtime version: .net9
Operating system: Cloud Cluster
Problem Description (expected vs. actual behavior):
I need to deserialize a DSL JSON into a SearchRequest object so that I can modify it before executing the query.
Here is the DSL query I am trying to deserialize:
{
"query": {
"bool": {
"must": {
"match": {
"Transcript": "unhappy customer at the end of the call"
}
},
"filter": [
{
"terms": {
"ClientId": ["4ft0g5n92pn8d3d8jv116gf15a"]
}
},
{
"nested": {
"path": "Phrases",
"query": {
"term": {
"Phrases.SpeakerId": "2"
}
}
}
}
]
}
}
}I attempted to deserialize it using the following C# code:
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(dslQuery));
searchRequest = await _elasticsearchClient.RequestResponseSerializer
.DeserializeAsync<SearchRequest>(memoryStream);However, this throws the following exception:
System.Text.Json.JsonException: 'Expected JSON 'StartObject' token, but got 'String'.'
I was able to run the same query successfully in Kibana, so I’m unsure why the serializer fails here. This may indicate an issue with the serializer options or the way SearchRequest expects the JSON structure.
Hi @MikeAlhayek ,
thanks for reporting!
This has a quite complex root cause. The backport of this PR to 8.19 failed without me noticing it. As a consequence, the code generator assumes that FieldValue might be an OBJECT type and generates incorrect code.
I'll see what we can do to fix this.
Fixed in 8.19.7.