我正在使用Nest 6.2.0连接到弹性搜索。
我试图映射包含DBGeography对象的类,并且尝试添加[GeoShape]标记,但出现以下错误。
ServerError = {ServerError:400Type:mapper_parsing_exception原因:“未能解析” CausedBy:“ Type: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));
此外,这是我要添加到索引中的Route对象的代码。
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?
答案 0 :(得分:0)
NEST不知道如何序列化DbGeography
类型。您有以下选项:
DbGeography
序列化为Elasticsearch支持的geo_shape geoJSON,并从hook up JsonNetSerializer
Nest.JsonNetSerializer
nuget package来使用此转换器。或
DbGeography
类型映射到NEST知道如何序列化的相应IGeoShape
类型,并在文档POCO上使用IGeoShape
。您可能可以利用NetTopologySuite和诸如WKTReader
之类的类型来帮助进行转换。 Elasticsearch 6.2.0支持将geo_shape输入作为WKT,但是在NEST中尚未公开。有an open issue to add it in the next release。至少,我希望这能支持将WKT反序列化为NEST的IGeoShape
。