【问题标题】:Indexing a unmapped/dynamically mapped document with a geopoint in elasticsearch NEST client在弹性搜索 NEST 客户端中使用地理点索引未映射/动态映射的文档
【发布时间】:2015-07-21 16:44:50
【问题描述】:

这是我在这个网站上的第一个问题,所以我会尝试正确地提出问题。

在使用 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 点之前,这不是问题。 如果这些不是作为地理点索引的,它们将不可搜索,当放置在字典中时,它们将默认为字符串。我无法覆盖它们。 地理点的数据以另一个名为 geofields 的字典的形式提供给代码。

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 注册为地理字段

Failed to find geo_shape field [locatiecoord]];

再次感谢任何帮助

【问题讨论】:

  • 嗨,罗伊,我有一个类似的,如果你已经解决了,请告诉我,我已经把我的问题放在这里了。 stackoverflow.com/questions/33579086/…
  • 嗨@Roy!你最后解决了吗?如果是,如何?谢谢!
  • 嗨,弗洛林,已经好几年了,但从未找到解决此问题的方法。

标签: c# elasticsearch nest


【解决方案1】:

根据文档,动态映射无法自动检测地理点。见Geo Points

【讨论】:

  • 嗨,@jrao77!不过,是否有解决方法可以做到这一点?谢谢!
【解决方案2】:

如果您像这样创建索引:

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”具有坐标值,那么您直接索引字典的初始方法将起作用。您可能可以根据类型(坐标)而不是名称(“MyShapeFieldName”)更改我的样本以匹配,但我尚未对此进行测试。

【讨论】:

    猜你喜欢
    • 2013-03-20
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    • 2015-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多