0

I'm trying to validate filter generation logic, so I have an instance of SearchRequest, but how to get a String representation of it ?

I don't have SearchResponse, only SearchRequest since I'm simply capturing it in my test.

This doesn't compile "Can't convert from NestSearchRequest" to byte[]. This doesn't work either, there is no Client class in Nest and ElasticClient doesn't have Serializer property (Nest 1.6.0/Elasticsearch 1.6.1).

Community
  • 1
  • 1
Rrr
  • 1,747
  • 3
  • 17
  • 22

1 Answers1

1

Here's a complete example for how to get the json representation of a query, using NEST 1.6.0

void Main()
{
    var client = new ElasticClient(connection: new InMemoryConnection());

    var query = Query<Document>.Match(m => m
        .OnField(f => f.Name)
        .Query("Match This Name")
    );

    var json = Encoding.UTF8.GetString(client.Serializer.Serialize(query));

    Console.WriteLine(json);
}

public class Document
{
    public string Name { get; set; }
}

which prints the following to the console

{
  "match": {
    "name": {
      "query": "Match This Name"
    }
  }
}
Russ Cam
  • 124,184
  • 33
  • 204
  • 266