【发布时间】:2019-01-29 00:43:22
【问题描述】:
我创建了 WEBAPI 方法,使用 NEST 搜索 ES。使用 ES 进行的搜索按预期工作。我遇到的问题是,当我尝试使用 POSTMAN 返回 Json(response) 时,它会引发此异常:
{ "Message": "发生错误。", "ExceptionMessage": "如果您使用自定义合约解析器,请务必从 ElasticContractResolver 子类化", "ExceptionType": "System.Exception", "StackTrace": " 在 Nest.JsonExtensions.GetConnectionSettings(JsonSerializer 序列化程序)\r\n 在 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 取消令牌)\r\n 在 System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- 从先前抛出异常的位置结束堆栈跟踪 ---\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)\r\n 在 System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- 从先前抛出异常的位置结束堆栈跟踪 ---\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)\r\n 在 System.Web.Http.Controllers.AuthenticationFilterResult.d__0.MoveNext()\r\n--- 从先前抛出异常的位置结束堆栈跟踪 ---\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)\r\n 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)\r\n 在 System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()" }
这是我的 WEB API 方法
[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.
我正在使用 Elasticsearch/NEST 5.x。
【问题讨论】:
标签: elasticsearch asp.net-web-api nest elasticsearch-5