gpt4 book ai didi

c# - Geo_Point 属性未按预期编制索引

转载 作者:太空宇宙 更新时间:2023-11-03 21:36:29 27 4
gpt4 key购买 nike

我正在使用 NEST .net 客户端进行 Elastic Search。我有一个带有 Location 属性的 Address 类。

public class Address
{
public string AddressLine1 {get;set;}
public string AddressLine2 {get;set;}
public string City {get;set;}
public string State {get;set;}
public string ZipCode {get;set;}
[ElasticProperty(Type = FieldType.geo_point)]
public GeoLocation Location {get;set;}
}


public class GeoLocation
{
public float Lat {get;set;}
public float Lon {get;set;}
}

我用 ElasticProperty 属性 geo_point 类型修饰了 Location 属性。我能够为这种类型建立索引。但是当我尝试为此获取映射时,

http://localhost:9200/mysite/Address/_mapping

我希望 Location 属性是“geo_point”类型,而不是它显示类似这样的内容。

{
"Address": {
"properties": {
"location": {
"properties": {
"lat": {
"type": "double"
},
"lon": {
"type": "double"
}
}
}
}
}
}

我在这里遗漏了什么吗?

最佳答案

这是一个完整的示例,说明如何使用 Nest 映射 GeoPoint 以及设置其他属性。希望对 future 的人有所帮助。

public class Location
{
public decimal Lat { get; set; }
public decimal Lon { get; set; }
}

public class Building : BaseEntity
{
public IEnumerable<Location> Location { get; set; }
}

public void CreateBuildingMapping()
{
var nodes = new List<Uri>() { ... };
var connectionPool = new Elasticsearch.Net.ConnectionPool.SniffingConnectionPool(nodes);
var connectionSettings = new Nest.ConnectionSettings(connectionPool, "myIndexName");
var elasticsearchClient = new Nest.ElasticClient(connectionSettings);

var putMappingDescriptor = new Nest.PutMappingDescriptor<Building>(connectionSettings);
putMappingDescriptor.DateDetection(false);
putMappingDescriptor.Dynamic(false);
putMappingDescriptor.IncludeInAll(true);
putMappingDescriptor.IgnoreConflicts(false);
putMappingDescriptor.Index("myIndexName");
putMappingDescriptor.MapFromAttributes();
putMappingDescriptor
.MapFromAttributes()
.Properties(p =>
p.GeoPoint(s =>
s.Name(n => n.Location).IndexGeoHash().IndexLatLon().GeoHashPrecision(12)
)
);
putMappingDescriptor.NumericDetection(false);

elasticsearchClient.Map(putMappingDescriptor);
}

我使用了他评论中的 Vinoths 代码。

关于c# - Geo_Point 属性未按预期编制索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21552791/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com