I have created WEBAPI methods, to search ES using NEST. The search with ES is working as expected. The issue that I have is when I try to return the Json(response) using POSTMAN, it throws this exception:
{ "Message": "An error has occurred.", "ExceptionMessage": "If you use a custom contract resolver be sure to subclass from ElasticContractResolver", "ExceptionType": "System.Exception", "StackTrace": " at Nest.JsonExtensions.GetConnectionSettings(JsonSerializer serializer)\r\n at Nest.VerbatimDictionaryKeysJsonConverter
2.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n at System.Web.Http.Results.JsonResult1.Serialize()\r\n at System.Web.Http.Results.JsonResult1.Execute()\r\n at System.Web.Http.Results.JsonResult1.ExecuteAsync(CancellationToken cancellationToken)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.AuthenticationFilterResult.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()" }
This is my WEB API method
[System.Web.Http.Route("SearchElastic")]
[System.Web.Http.HttpPost]
public JsonResult<ISearchResponse<T>> SearchElastic([FromBody] ElasticSearchRequest esRequest)
{
var searchResponse = EsClient.Search<T>(
"...NEST query..."
));
return Json(searchResponse);
}
//<T> is a custom C# class.
I am using Elasticsearch/NEST 5.x.