簡體   English   中英

使用elasticsearch NEST客戶端中的geopoint索引未映射/動態映射的文檔

[英]Indexing a unmapped/dynamically mapped document with a geopoint in elasticsearch NEST client

這是我在這個網站上的第一個問題,所以我會試着提出正確的問題。

在使用elasticsearch nest客戶端時,我使用批量索引來存儲我的數據。 所有數據都可以在Dictionary<string, object>的幫助下編制索引。 我工作的公司堅持動態映射,這意味着我不允許聲明轉到節點的變量。

Dictionary <string, object> document_value= new Dictionary<string, object>();
Bulkcontainer.Index<object>(i => i.Index(index_name).Type(_type).Id(_id).Document(document_value));

在使用GEO點之前,這不是問題。 如果它們沒有被編入索引作為地理位置,則它們將無法搜索,當放置在dictonary時它們將默認為字符串。 我無法覆蓋它們。 geopoint的數據以另一個名為geofields的dictonary形式提供給代碼。

PointGeoShape coord = new PointGeoShape();
    Dictionary<string, PointGeoShape> geovalue = new Dictionary<string, PointGeoShape>();
    if (geofields!= null)
    {
        foreach (KeyValuePair<string, object> geo in geofields)
        {
            string veldnaam = geo.Key.ToUpper();
            string temp = geo.Value.ToString();
            if (temp != "")
            {
                string[] array = temp.Split(new char[] { ',' }, 2);
                List<double> list = new List<double>();
                list.Add(double.Parse(array[0]));//lon
                list.Add(double.Parse(array[1]));//lat
                IEnumerable<double> latlon = list;
                coord.Coordinates = latlon;
                document_value.Add(veldnaam, coord);
            }
        }
     }

任何幫助澄清我的問題將不勝感激


我將索引類型更改為

public class ES_DATA_GEO
{
public Dictionary<string, object> Data { get; set; }
[ElasticProperty(Type = Nest.FieldType.GeoShape)]
public GeoShape Locatiecoord { get; set; }
}

但是現在當我執行查詢時,它仍然沒有將Locatiecoord注冊為Geo字段

Failed to find geo_shape field [locatiecoord]];

再次感謝任何幫助

根據文檔,無法使用動態映射自動檢測地理點。 查看地理點數

如果你像這樣創建索引:

var created = client.CreateIndex("MyIndexName", 
    c => c.AddMapping<dynamic>(m => m.Type("_default_").
    DynamicTemplates(t => t.Add(f => f.Name("shape_fields")
    .Match("MyShapeFieldName").Mapping(ma => ma.GeoPoint(s => 
    s.IndexGeoHash().IndexLatLon()))))

然后,假設您的詞典中有一個條目“MyShapeFieldName”具有Coordinate值,那么直接索引字典的初始方法將起作用。 您可以根據類型(坐標)而不是名稱(“MyShapeFieldName”)更改我的樣本以匹配,但我還沒有測試過。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM