Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

This is my first question on this website so i will try to ask the question correct.

while working with the elasticsearch nest client i use bulk indexing to store my data. All the data can be indexed with the help of a Dictionary<string, object>. The company i work for insists on dynamic mapping, which means i am not allowed to declare the variables that go to the nodes.

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

This wasnt a problem until the use of GEO points. if these arent indexed as geopoints they will not be searchable, when placed in the dictonary they will default to string. i am not able to override them. the data for geopoint are given to the code in the form of another dictonary called 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);
            }
        }
     }

any help to clarify my problem will be appreciated


i changed the index type to

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

but now when i execute the query it still doesnt register Locatiecoord as Geo field

Failed to find geo_shape field [locatiecoord]];

again any help is appreciated

like image 717
Roy Avatar asked May 11 '15 08:05

Roy


1 Answers

According the docs, geo points cannot be automatically detected with dynamic mapping. See Geo Points

like image 72
jrao77 Avatar answered Oct 03 '22 08:10

jrao77