c# - ElasticSearch PostData 序列化插入不起作用
问题描述
这是我的发布方法
[HttpPost]
public IActionResult InsertEmployee([FromForm]Employee model)
{
var Employee = new Employee
{
EmpId = 3,
Name = "asadasasad",
Country = "pak",
Gender = false,
StartDate = DateTime.Now.Date,
MultiCheck = "3,2,1"
};
PostData fromObject = PostData.Serializable(Employee);
_elasticClient.Index(fromObject, i => i
.Index("employee"));
string message = "Failed to create the product. Please try again";
return Content(message);
}
使用此方法时,它会增加值但不会显示在记录上
http://localhost:9200/employee/_search?typed_keys=true?size=1000
此查询返回此响应
解决方案
在 Elastic Search Post Data insert 中,您首先需要序列化将其转储到类中的对象,然后对其进行反序列化,然后使用这种方式插入到 elasticsearch
var data = JsonConvert.DeserializeObject<NetConnectTransactionDTO>(deserialize);
var Response = _elasticClient.Index(data, i => i
.Index(NetConnectTransactionIndex));
推荐阅读
- vba - 访问 VBA - FindFirst 找不到真正存在的代码
- java - 如何在 RestEasy 中支持逗号分隔的列表 queryParam
- c# - 通过实体框架访问身份声明(使用 Automapper 投影和 PredicateBuilder)
- ruby-on-rails - 将表单重构为部分
- angularjs - 如何解决未捕获的错误:angularjs 中的 [$injector:modulerr]
- javascript - angular.js 未捕获错误:[ng:areq] 参数 'fn' 不是函数,在处理基于 angular-ui-calendar 的日历小部件时得到 Moment
- json - react native如何过滤JSON
- android - 无法将 Android 库资源设为私有?
- python - Django - 从一个应用程序重定向到另一个应用程序的页面 Django
- java - Android Retrofit 连接 JAVA 套接字