gpt4 book ai didi

elasticsearch - 我如何将lat和lng映射到elasticsearch中的geo_point类型

转载 作者:行者123 更新时间:2023-12-02 23:15:04 25 4
gpt4 key购买 nike

我正在使用elasticsearch 7和nest 6.7。

我有任何类型的索引,例如坐标。

无论如何我映射geo_type我有问题。

 client.CreateIndex("staging2", c => c.Mappings(m => m.Map<VenueIndex>(mm => mm.AutoMap())));

这是我的嵌套代码,这是我poko类的一部分:
     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

另一种方式,当我用户发布人仍然有这个问题。

我的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 - 我如何将lat和lng映射到elasticsearch中的geo_point类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56337105/

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