简体   繁体   English

使用NEST C#进行ElasticSearch 2.x GeoPoint映射

[英]ElasticSearch 2.x GeoPoint mapping with NEST C#

Im having a problem mapping "Geo Point" in elasticsearch using NEST C# Client. 我在使用NEST C#Client在elasticsearch中映射“Geo Point”时遇到问题。

Here is my class definition: 这是我的班级定义:

 [GeoPoint(Name = "coordinates", LatLon = true)]
  public Coordinates Coordinates { get; set; }

 public class Coordinates
 {
    [Number(NumberType.Double, Name = "lat")]
    public double Lat { get; set; }

    [Number(NumberType.Double, Name = "lng")]
    public double Lng { get; set; }
 }

My mapping properties on Index creation: 我在索引创建时的映射属性:

.Mappings(map => map
    .Map<Crime>(m => m.AutoMap()
    .TimestampField(ts => ts.Enabled(true).Path("timeStamp"))                                                
    .Properties(pro => pro
      .GeoPoint(geo => geo
         .Name(n => n.Coordinates)
         .LatLon(true)
))))

And my mapping doesnt look right once some documents were indexed.... 一旦某些文档被编入索引,我的映射看起来并不正确....

...
"coordinates": {
                  "properties": {
                     "lat": {
                        "type": "double"
                     },
                     "lng": {
                        "type": "double"
                     }
                  }
               },
...

And when i try querying it (using SENSE) I get the following error: 当我尝试查询它(使用SENSE)时,我收到以下错误:

"reason": {
               "type": "query_parsing_exception",
               "reason": "failed to parse [geo_bbox] query. could not find [geo_point] field [coordinates]",
               "index": "someindexname",
               "line": 16,
               "col": 9
            }

So in my opinion the problem is with my mapping, but everything has changed quite drastically in 2.x update (compared to 1.x) that I dont know how to map a geo point properly. 所以在我看来问题是我的映射,但是2.x更新(与1.x相比)的所有内容都发生了巨大的变化,我不知道如何正确映射地理点。 Any Ideas ? 有任何想法吗 ?

Solved - updated NEST library to the newest release - 解决 - 更新NEST库到最新版本 -

And also renamed my Coordinates class member Lng to Lon: 并且还将我的Coordinates类成员Lng重命名为Lon:

[Number(NumberType.Double, Name = "lon")]
public double Lon { get; set; }

I think the C# declaration doesnt matter its just the annotation thats important. 我认为C#声明并不重要,只是注释很重要。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM