c# - 带有 NEST 的索引 JsonObject 具有空值
问题描述
我想用 NEST 索引 JsonObjects,发布后属性在索引中,但值为空“[]”。当我使用 Postman 发布相同的 json 时,结果是正确的。
指数:
string indexName = "testindex";
IIndexResponse response = client.Index<JObject>(docItem, i => i.Type("my_type").Index(indexName));
docItem中的json:
{
"Source":"test",
"CreatedAt": "2018-05-26 12:23:33",
"SessionId":"1234",
"ResponseParam":{
"ItemA":"bla",
"ItemB": 123
}
}
搜索查询:
http://[IP]:9200/testindex/_search
搜索结果
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "testindex",
"_type": "my_type",
"_id": "u44ucmMB687Uyj7O8xKY",
"_score": 1,
"_source": {
"Source": [],
"CreatedAt": [],
"SessionId": [],
"ResponseParam": {
"ItemA": [],
"ItemB": []
}
}
},
解决方案
如果您使用 JObject 作为文档类型,或者您的文档包含 JObject,您还需要引用 NEST.JsonNetSerializer nuget 包并连接 JsonNetSerializer,如下所示
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings =
new ConnectionSettings(pool, sourceSerializer: JsonNetSerializer.Default);
var client = new ElasticClient(connectionSettings); 这是必需的,因为 NEST 6.x 通过 IL 合并、内部化和重新命名空间删除了对 Json.NET 的直接依赖。这带来的变化之一是,现在 NEST 不知道如何专门处理 Newtonsoft.Json.Linq.JObject,因此需要依赖确实知道如何专门处理该类型的 NEST.JsonNetSerializer。
来源:https ://discuss.elastic.co/t/elasticsearch-net-nest-issue-with-api-after-upgrade-to-6-2-3/127690
推荐阅读
- here-api - 我如何理解此处车队远程信息处理 API 的经纬度编码?(例如层。ROAD_GEOM_FC5)
- python - 使用 Python 将嵌套的 JSON 数据附加到列中
- node.js - 如何捕捉系统声音
- javascript - 对异步和承诺的困惑。反应原生
- apache-spark - Spark-shell:当我执行进程时,Web UI 不会改变
- css - 悬停剪辑
- javascript - Javascript:连续 for 循环
- spring-boot - 从部署在 PCF 上的另一个 Java 应用程序调用一个 Java 应用程序
- flutter - 颤动光标轮小部件自动定位动画
- java - Android Studio onCheckedChanged 方法