我使用Nest 6.2.0连接到弹性搜索。
我正在试图映射一个包含DBGeography对象的类,并且我尝试添加了GeoShape标记,得到了以下错误。
ServerError = {ServerError: 400Type: mapper_parsing_exception原因:“未能解析”CausedBy:“类型: not_x_content_exception原因:”压缩机检测只能在某些xcontent字节或压缩xcontent字节上调用“”}
用于创建索引和文档的代码是:
// Create an index
response = Connection.CreateIndex(indexName, c => c
.Mappings(ms => ms
.Map<RACE.DataModels.EventModels.Event.Route>(m => m
.AutoMap<RACE.DataModels.EventModels.Event.Route>()
)
)
);
// Add document to index
result = Connection.Index(obj, i => i
.Index(indexName));另外,下面是我试图添加到索引中的路由对象的代码。
public partial class Route : BaseClass
{
[Key]
public Guid ID { get; set; }
[Required]
[Display(Name = "Event")]
public Guid EventID { get; set; }
[Required]
[Display(Name = "Route Name")]
public string Name { get; set; }
[Display(Name = "Description")]
public string Description { get; set; }
[Required]
[Display(Name = "Path Type")]
public int PathType { get; set; }
[GeoShape]
[Required]
[Display(Name = "Route Path")]
public DbGeography Path { get; set; }
//[GeoShape]
[Ignore]
public string PathWKT { get { return Path.WellKnownValue.WellKnownText; } }
[GeoShape]
[Display(Name = "Start")]
public DbGeography Start { get; set; }
[GeoShape]
[Display(Name = "End")]
public DbGeography End { get; set; }
[Display(Name = "Laps")]
public int Laps { get; set; }
[Display(Name = "Status")]
public int Status { get; set; }
[Ignore]
[ForeignKey("EventID")]
public virtual Event Event { get; set; }
[Ignore]
[ForeignKey("RouteID")]
public virtual List<Gateway> Gateways { get; set; }
}DBGeography是否阻止对象被正确映射,我如何才能正确地将DBGeography对象映射到GeoShape?
发布于 2018-08-11 00:44:16
NEST不知道如何序列化DbGeography类型。你有以下选择:
DbGeography序列化为Elasticsearch支持的geo_shape geoJSON,并从nuget包装编写JsonNetSerializer来使用此转换器。或
DbGeography类型映射到嵌套知道如何序列化的相应IGeoShape类型,并在文档POCO上使用IGeoShape。您可能可以利用NetTopologySuite和类型(如WKTReader )来帮助进行转换。ElasticSearch6.2.0支持形状输入作为WKT,但它还没有公开在NEST中;还有将其添加到下一个版本中的未决问题。。至少,我预计这将支持反序列化WKT到NEST的IGeoShape。
https://stackoverflow.com/questions/51786837
复制相似问题