Skip to content

Expected JSON 'StartObject' token, but got 'String'. #8713

@MikeAlhayek

Description

@MikeAlhayek

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions