带有 NEST 的索引 JsonObject 具有空值
Index JsonObject with NEST has empty values
我想用 NEST 索引 JsonObjects,在 posting 属性在索引中但值为空“[]”之后。当我 post 与 Postman 相同 json 结果是正确的。
索引:
string indexName = "testindex";
IIndexResponse response = client.Index<JObject>(docItem, i => i.Type("my_type").Index(indexName));
json 在 docItem:
{
"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
我想用 NEST 索引 JsonObjects,在 posting 属性在索引中但值为空“[]”之后。当我 post 与 Postman 相同 json 结果是正确的。
索引:
string indexName = "testindex";
IIndexResponse response = client.Index<JObject>(docItem, i => i.Type("my_type").Index(indexName));
json 在 docItem:
{
"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