Please help with querying geospatial data -- geopoint and geoshape with NEST API

I am working with data ingested via Logstash, which has these fields among others:

 "location_center": [
      20.4222935,
      44.815367
    ],
    "location": {
      "type": "envelope",
      "coordinates": [
        [
          20.221376,
          44.942688
        ],
        [
          20.623211,
          44.688046
        ]
      ]
    }

I can't seem to find a way to search by their values, like matching all that are contained inside given coordinates. I tried both in Kibana data view and via NEST.

Here is my C# code:

var local = new Uri("http://localhost:9200");
            var settings = new ConnectionSettings(local).DefaultIndex("lyrics_data");
            var client = new ElasticClient(settings);
            var searchResponse = client.Search<Song>(s => s.PostFilter
                        (f => f.Bool(b => b
                          .Must(mu =>
                          {
                            return mu;
                          }
                        )))                        
                        .Query(q => q.Bool(b => b
                          .Must(mu =>
                          {
                          
                              if (Location != "All")
                              {
                                  mu.GeoShape(c => c
                                    .Field(p => p.Location)
                                    .Shape(s => s
                                        .Envelope(getSelectedNW(), getSelectedSE())
                                     )
                                        .Relation(GeoShapeRelation.Contains));

                              }         
                              return mu;
                          })
                          )
                        )
                    );

            var songs = new List<Song>();
            foreach (var hit in searchResponse.Hits)
            {
                songs.Add(hit.Source);
            }
            return songs;

getSelectedNW and getSelectedSE return GeoCoordinate points.
I don't know how to define location and location_center in POCO. Object doesn't work. Excerpt from Song POCO:

 [Object(Name = "location")]
        public Object Location { get; set; }

@nreese / @nickpeihl can you throw some light on this when you find time?

Thanks
Rashmi

Let's focus first in the pure Elasticsearch side and maybe later you can continue with the NEST part. Can you share the mapping of your index, at least for the location and location_center fields?

Thank you, it was as trivial as mixing coordinate order in GeoShape objects returned by ```
getSelectedNW(), getSelectedSE().

1 Like