I've been digging deeper into using NEST for a .Net based project that shall utilize ElasticSearch but what keeps or kept puzzling me is that GeoDistance queries never returned any results.
When debugging into the responses for a simple "*" query and looking at the .Documents of the search result, all document instances have a Longitude value of 0.0 - Latitude however is the correct one.
This is a bare-bones ES server as fresh as it gets (download and run), nothing (re-)configured.. same for one hosted at FacetFlow.
As for versions, they are 1.4.3 for Elasticsearch.Net and also NEST, ElasticSearch itself is version 1.4.4.
Is there anything I am missing here or more precisely - what am I missing here?
The sample code looks like this (the GeoLocation class used below is the Nest.GeoLocation one):
using System;
using System.Linq;
using Nest;
namespace NestPlayground
{
public class Post
{
public Guid Id { get; set; }
public string User { get; set; }
public DateTime CreatedAt { get; set; }
public string Message { get; set; }
public GeoLocation Location { get; set; }
}
class Program
{
static void Main(string[] args)
{
var indexName = "sampleindex";
var uri = new Uri("<elasticsearch url>");
var settings = new ConnectionSettings(uri).SetDefaultIndex(indexName);
var client = new ElasticClient(settings);
client.DeleteIndex(indexName);
var post = new Post
{
Id = Guid.NewGuid(),
User = "Some User",
CreatedAt = DateTime.UtcNow,
Message = "Some Sample Message",
Location = new GeoLocation(37.809860, -122.476995)
};
client.Index(post);
client.Refresh();
// Execute a search using the connection from above.
var result = client.Search<Post>(s => s
.Index(indexName)
.Query(queryDescriptor => queryDescriptor.QueryString(queryStringQueryDescriptor => queryStringQueryDescriptor.Query("*")))
//.Filter(filterDescriptor => filterDescriptor.GeoDistance(post1 => post1.Location, geoDistanceFilterDescriptor => geoDistanceFilterDescriptor
// .Distance(50, GeoUnit.Kilometers)
// .Location(Lat: 37.802774, Lon: -122.4478561)
// .Optimize(GeoOptimizeBBox.Indexed)))
);
// this DOES return the just created/indexed document, but its .Longitude / result.Documents.First().Location.Longtitude property is always '0'?!
}
}
}