我如何将 lat 和 lng 映射到 elasticsearch 中的 geo_point 类型
how can i map lat and lng to geo_point type in elasticsearch
我正在使用 elasticsearch 7 和 nest 6.7。
我有任何类型的索引,例如 coordinate 。
无论如何我映射geo_type我有问题。
client.CreateIndex("staging2", c => c.Mappings(m => m.Map<VenueIndex>(mm => mm.AutoMap())));
这是我的嵌套代码,这是我的 poko class 的一部分
public object Promotion { get; set; }
public object Checkin { get; set; }
public Featured Featured { get; set; }
public int BinaryType { get; set; }
public List<WorkingHour> WorkingHours { get; set; }
[GeoPoint(Name = "location", IgnoreMalformed = true)]
public Geoloc _geoloc { get; set; }
public string Neighbourhood { get; set; }
public List<int> MealTimes { get; set; }
public string objectID { get; set; }
public class Geoloc
{
[Number(NumberType.Double, Name = "lat")]
public double lat { get; set; }
[Number(NumberType.Double, Name = "lon")]
public double lon { get; set; }
}
这样GeoLoc类型就是float
其他方式,当我的用户 post 仍然有这个问题。
我的 json 对象是这样的:
{
"isClubMember": false,
"rating": 0.0,
"binaryType": 2,
"location": {
"lat":"32.11",
"lon":"-34.22"
},
"neighbourhood": "شهرک والفجر,امیر آباد",
"mealTimes": [],
"objectID": "188dc91e-8088-4099-9eb8-00aa73653192"}
我的错误在哪里?
型号:
public class TestClass
{
public object Promotion { get; set; }
public object Checkin { get; set; }
[GeoPoint(Name = "location", IgnoreMalformed = true)]
public Geoloc _geoloc { get; set; }
public string Neighbourhood { get; set; }
public List<int> MealTimes { get; set; }
public string objectID { get; set; }
}
public class Geoloc
{
[Number(NumberType.Double, Name = "lat")]
public double lat { get; set; }
[Number(NumberType.Double, Name = "lon")]
public double lon { get; set; }
}
使用 NEST 创建映射的代码
var url = "http://localhost:9200";
var settings = new ConnectionSettings(new Uri(url));
EsClient = new ElasticClient(settings);
if (!EsClient.IndexExists("gcheck").Exists)
{
var resp = EsClient.CreateIndex("gcheck", c => c
.Map<TestClass>(mp => mp
.Properties(
ps => ps
).AutoMap()
));
}
输出映射:
"gcheck" : {
"mappings" : {
"properties" : {
"binaryType" : {
"type" : "long"
},
"checkin" : {
"type" : "object"
},
"isClubMember" : {
"type" : "boolean"
},
"location" : {
"type" : "geo_point",
"ignore_malformed" : true
},
"mealTimes" : {
"type" : "integer"
},
"neighbourhood" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"objectID" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"promotion" : {
"type" : "object"
},
"rating" : {
"type" : "long"
}
}
}
}
我正在使用 elasticsearch 7 和 nest 6.7。
我有任何类型的索引,例如 coordinate 。
无论如何我映射geo_type我有问题。
client.CreateIndex("staging2", c => c.Mappings(m => m.Map<VenueIndex>(mm => mm.AutoMap())));
这是我的嵌套代码,这是我的 poko class 的一部分
public object Promotion { get; set; }
public object Checkin { get; set; }
public Featured Featured { get; set; }
public int BinaryType { get; set; }
public List<WorkingHour> WorkingHours { get; set; }
[GeoPoint(Name = "location", IgnoreMalformed = true)]
public Geoloc _geoloc { get; set; }
public string Neighbourhood { get; set; }
public List<int> MealTimes { get; set; }
public string objectID { get; set; }
public class Geoloc
{
[Number(NumberType.Double, Name = "lat")]
public double lat { get; set; }
[Number(NumberType.Double, Name = "lon")]
public double lon { get; set; }
}
这样GeoLoc类型就是float
其他方式,当我的用户 post 仍然有这个问题。
我的 json 对象是这样的:
{
"isClubMember": false,
"rating": 0.0,
"binaryType": 2,
"location": {
"lat":"32.11",
"lon":"-34.22"
},
"neighbourhood": "شهرک والفجر,امیر آباد",
"mealTimes": [],
"objectID": "188dc91e-8088-4099-9eb8-00aa73653192"}
我的错误在哪里?
型号:
public class TestClass
{
public object Promotion { get; set; }
public object Checkin { get; set; }
[GeoPoint(Name = "location", IgnoreMalformed = true)]
public Geoloc _geoloc { get; set; }
public string Neighbourhood { get; set; }
public List<int> MealTimes { get; set; }
public string objectID { get; set; }
}
public class Geoloc
{
[Number(NumberType.Double, Name = "lat")]
public double lat { get; set; }
[Number(NumberType.Double, Name = "lon")]
public double lon { get; set; }
}
使用 NEST 创建映射的代码
var url = "http://localhost:9200";
var settings = new ConnectionSettings(new Uri(url));
EsClient = new ElasticClient(settings);
if (!EsClient.IndexExists("gcheck").Exists)
{
var resp = EsClient.CreateIndex("gcheck", c => c
.Map<TestClass>(mp => mp
.Properties(
ps => ps
).AutoMap()
));
}
输出映射:
"gcheck" : {
"mappings" : {
"properties" : {
"binaryType" : {
"type" : "long"
},
"checkin" : {
"type" : "object"
},
"isClubMember" : {
"type" : "boolean"
},
"location" : {
"type" : "geo_point",
"ignore_malformed" : true
},
"mealTimes" : {
"type" : "integer"
},
"neighbourhood" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"objectID" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"promotion" : {
"type" : "object"
},
"rating" : {
"type" : "long"
}
}
}
}