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

**URL:** <https://discuss.elastic.co/t/please-help-with-querying-geospatial-data-geopoint-and-geoshape-with-nest-api/311546>\
**Category:** Elasticsearch\
**Tags:** language-clients, ingest-pipeline\
**Created:** [August 5, 2022, 2:02pm UTC](https://discuss.elastic.co/t/please-help-with-querying-geospatial-data-geopoint-and-geoshape-with-nest-api/311546 "2022-08-05T14:02:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dragana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dragana/32/97710_2.png) [@Dragana](https://discuss.elastic.co/u/Dragana)\
**Post date:** [August 5, 2022, 2:02pm UTC](https://discuss.elastic.co/t/please-help-with-querying-geospatial-data-geopoint-and-geoshape-with-nest-api/311546/1 "2022-08-05T14:02:09Z")

</div>

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

```auto
 "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:

```auto
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:

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

```

---

<div class="post-metadata">

**Author:** ![rashmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi/32/16391_2.png) [@rashmi](https://discuss.elastic.co/u/rashmi)\
**Post date:** [August 8, 2022, 4:27am UTC](https://discuss.elastic.co/t/please-help-with-querying-geospatial-data-geopoint-and-geoshape-with-nest-api/311546/2 "2022-08-08T04:27:08Z")

</div>

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

Thanks  
Rashmi

---

<div class="post-metadata">

**Author:** ![jsanz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsanz/32/53734_2.png) [@jsanz](https://discuss.elastic.co/u/jsanz)\
**Post date:** [August 9, 2022, 9:46am UTC](https://discuss.elastic.co/t/please-help-with-querying-geospatial-data-geopoint-and-geoshape-with-nest-api/311546/3 "2022-08-09T09:46:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Dragana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dragana/32/97710_2.png) [@Dragana](https://discuss.elastic.co/u/Dragana)\
**Post date:** [August 12, 2022, 9:31am UTC](https://discuss.elastic.co/t/please-help-with-querying-geospatial-data-geopoint-and-geoshape-with-nest-api/311546/4 "2022-08-12T09:31:19Z")

</div>

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

```auto

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 9, 2022, 9:31am UTC](https://discuss.elastic.co/t/please-help-with-querying-geospatial-data-geopoint-and-geoshape-with-nest-api/311546/5 "2022-09-09T09:31:52Z")

</div>

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