【发布时间】:2019-01-22 15:30:51
【问题描述】:
我们正在从 elasticsearch 5.2 升级到 elasticsearch 6.4.2,因此也从 Nest 5.0.1 升级到 Nest 6.4.2。 在 5.0.1 中,我们可以将 geoJSON 数据作为对象进行索引,但 Nest 6.4.2 会生成一个包含没有数据的 geoJSON 的请求。
我们将带有 geoJSON 格式的地理数据的字段索引到 elasticsearch 中的 geoshape 字段,如下所示:
在 GeoDocument 类中:
[Nest.Text(Name = "field1")]
public string Field1 { get; set; }
[Nest.GeoShape(Name = "geometrie")]
public object Geometrie { get; set; }
数据:
string polygon = "{\"type\":\"Polygon\",\"coordinates\":[[[5.856956,51.002753],[5.856928,51.002771],[5.856687,51.002853],[5.856956,51.002753]]]}";
将数据序列化为对象:
Geometrie = JsonConvert.DeserializeObject<object>(polygon);
Nest 5.0.1 中的索引文档(运行良好):
var response = this.ElasticClient.Index<T>(geoDocument);
Nest 6.4.2 中的索引文档:
var response = this.ElasticClient.IndexDocument<T>(geoDocument);
请求应该是这样的:
{"field1":"correct content","geometrie":{"type":"Polygon","coordinates"::[[[5.856956,51.002753],[5.856928,51.002771],[5.856687,51.002853],[5.856956,51.002753]]]}}
但 Nest 会生成如下请求:
{"field1":"correct content","geometrie":{"type":[],"coordinates":[[[[],[]],[[],[]],[[],[]],[[],[]]]]}}
回复:
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse field [geometrie] of type [geo_shape]"}],"type":"mapper_parsing_exception","reason":"failed to parse field [geometrie] of type [geo_shape]","caused_by":{"type":"illegal_state_exception","reason":"Can't get text on a START_ARRAY at 1:673"}},"status":400}
我们不会在连接设置中注入 SourceSerializerFactory。
【问题讨论】:
-
您能否提供一个完整、最小且可验证的示例来复制您所看到的内容(请参阅常见问题解答:stackoverflow.com/help/mcve)?我怀疑在这种情况下
object是Json.NETJObject类型,客户端不知道如何专门处理它,而没有连接JsonNetSerializer。如果你能提供一个完整的例子,我将能够提供进一步的帮助
标签: c# elasticsearch nest