如何使用NEST(C#)在Elasticsearch中上载GeoJson文件/为其编制索引

问题描述 投票:0回答:1

我有GeoJson文件,我想通过NEST在Elastic Search上建立索引但是由于缺乏专业知识,我在索引文档时遇到了麻烦我创建了一个类,表示在ElasticSearch上的映射:

public class GeoDocument
    {
        [Nest.Keyword(Name = "DocId")]
        public string DocId { get; set; }

        [Nest.GeoShape(Name = "GeoField")]
        public object GeoField { get; set; }
    }

但是当我使用此映射为文档建立索引时


var polygon = "{\"type\":\"Polygon\",\"coordinates\":[[[5.856956,51.002753],[5.856928,51.002771],[5.856687,51.002853],[5.856956,51.002753]]]}";

var geoDocument = new GeoJson
{
   DocId = "1",
   GeoField = JsonConvert.DeserializeObject<object>(polygon)
};
var IndexResponse = client.IndexDocument(geoDocument);

我得到这样的结果

"_source": {
                    "DocId": "1",
                    "GeoField": [
                        [
                            []
                        ],
                        [
                            [
                                [
                                    [
                                        [],
                                        []
                                    ],
                                    [
                                        [],
                                        []
                                    ],
                                    [
                                        [],
                                        []
                                    ],
                                    [
                                        [],
                                        []
                                    ]
                                ]
                            ]
                        ]
                    ]
                }
            }
c# elasticsearch nest
1个回答
0
投票
为了正确保存JObject,您必须告诉ElasticClient使用NewtonSoft .Net序列化程序。
© www.soinside.com 2019 - 2024. All rights reserved.