We have an index with a GeoShape field that contains boundaries of counties in WKT format such as MULTIPOLYGON (((-9.50189821688122 51.6790656404768, -9.52975113548365 51.6846028881403, -9.49436480898325 51.7002020861983, -9.501898216881 etc. etc.
We also have an index that has properties each with a Lat/Lng co-ordinates in another index.
How can we find which properties are within a particular county using the NEST syntax
Many thanks for your reply.
To save us re-indexing:
1-Do we have to make our location (points i.e. lat/lng) as GeoShape?
2-Is there anyway to keep points(lat/lng) as GeoPoints?
Yes, if you want to use them with a geo_shape query
I would suggest keeping points as geo_point if you need to run queries and aggregations that accept geo_point, and also indexing as geo_shape for geo_shape queries.
If you have already indexed the data, you can
Add a new field to the mapping of type geo_shape e.g. field named shape
Run an update_by_query to index the geo_point data into the new geo_shape field, using a script. Something like
var putMappingResponse = client.Map<object>(c => c
.Index(pointsIndex)
.Properties(p => p
.GeoShape(g => g
.Name("geo_shape")
)
)
);
var updateByQueryResponse = client.UpdateByQuery<object>(u => u
.Index(pointsIndex)
.Script(@"
ctx._source['geo_shape'] = [
'type': 'point',
'coordinates': ctx._source.geo_point
]
")
.Refresh(true)
);
This assumes an existing geo_point field called "geo_point". It updates the mapping to add a new geo_shape field called "geo_shape", then runs an update_by_query to create the geo shape for each document from the existing geo point in _source.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.