Problems setting up documents using geo_point

I am using C# Nest version 8, and have an Index of hotels with GeoLocation.

My document have the following property:

public GeoCoordinate geoCoordinate { get; set; }

When I try to do a geo search I end up with an empty array:

var result = await _client.SearchAsync<EHotel>(s => s
    .Index(HotelIndex)
    .Size(5000)
    .Query(q => q
        .GeoDistance(gd => gd
            .Field(f => f.geoCoordinate)
            .DistanceType(GeoDistanceType.Arc)
            .Location(coordinate)
            .Distance(distance, DistanceUnit.Kilometers)
        ))
    .Explain()
);

I've been searching a lot on the topic but seems I'm not able to find the a solution.

When I go to Kibana, the geoCoordinate property is a number and not a geo_point.

Can someone help me how to solve this with nest?

Have you created the mapping for your field before indexing any data?

Can you share your mappings? A geo_point field needs to be mapped before indexing any data on it.

I could indeed be the case.

I'm not sure how to see the mappings in Nest 8.

I'm not sure how you would do it as well as I do not use it and I always set the mapping using templates, never directly on code.

But if you didn't created the mapping for the geo_point then it will not work as a geo_point, the mapping needs to be created before indexing the data.

You can read more about it here.

1 Like

I found a way to get the mapping, and you're right the mappings are wrong.

var response = _client.Indices.GetMapping<StringResponse>(m => m.Index(HotelIndex));
var index = response.Indices.FirstOrDefault();
var mapproperties = index.Value.Mappings.Properties;

I look into a way to create the index, and see if automap solves the issues.

Thanks for reaching out :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.