I have indexed a document including a SpatialRecursivePrefixTreeFieldType
field named 'geo'. I was reading about the Geospatial formatter and wanted to try it but I can't seem to get it to work.
Here is an example document I have indexed:
{
"geo": "POLYGON((22.376144 -50.055954, 36.013237 -50.055954, 36.013237 -47.949005, 22.376144 -47.949005, 22.376144 -50.055954))",
"id": "a3ca6c69-acb9-30e6-b1a6-dbfd72917bc8",
"val_d": 33.067356,
"_version_": 1541776337602084900,
"insert_timestamp": "2016-08-04T23:14:54.814Z"
}
And this is the query I am trying:
q=id%3A%22a3ca6c69-acb9-30e6-b1a6-dbfd72917bc8%22&rows=1&fl=*%2C%5Bgeo+f%3Dgeo+w%3DGeoJSON%5D&wt=json&indent=true
In a more readable format:
q=id:"a3ca6c69-acb9-30e6-b1a6-dbfd72917bc8"
rows=1
fl=*,[geo f=geo w=GeoJSON]
wt=json
indent=true
The result I get back is simply the indexed document exactly as I quoted above. I also tried modifying the fl
argument to include a key like this fl=*,geojson[geo f=geo w=GeoJSON]
but that doesn't work either.
Is there a reason I can't get the formatter to work?
Version info:
The geospatial transformer was added in version 6.1 according to:
https://issues.apache.org/jira/browse/SOLR-8814
With minor changes, we can modify the existing JSON writer to produce a GeoJSON
FeatureCollection
for ever SolrDocumentList. We can then pick a field to use as the geometry type, and use that for the Feature#geometry"response":{"type":"FeatureCollection","numFound":1,"start":0,"features":[ {"type":"Feature", "geometry":{"type":"Point","coordinates":[1,2]}, "properties":{ ... the normal solr doc fields here ...}}] }}
This will allow adding solr results directly to various mapping clients like Leaflet This patch will work with Documents that have a spatial field the either: 1. Extends AbstractSpatialFieldType 2. has a stored value with geojson 2. has a stored value that can be parsed by spatial4j (WKT, etc) The spatial field is identified with the parametergeojson.field
It is marked as
Fix Version/s: 6.1, master (7.0)
So the answer to the question is; an upgrade to Solr 6.1 is required for the geospatial formatter to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With