Friday, August 7, 2020

Indexing Spatial data(Multipolygons) on Solr

Note: Good as of v8.6


  • Copy JTS jar to SOLR_INSTALL/server/solr-webapp/webapp/WEB-INF/lib


  • Update location_rpt field type on schema xml to:

        <fieldType name="location_rpt"
            class="solr.SpatialRecursivePrefixTreeFieldType"
            autoIndex="true"
            validationRule="repairBuffer0"
            spatialContextFactory="JTS"
            geo="true" distErrPct="0.025" maxDistErr="0.001"
            distanceUnits="degrees" />

  • change the geometry field's data type to location_rpt and make it multivalued
  • To index, assign WKT value to the geometry field.
  • To query for all polygons within a bounding box:

q    *:*
fq        geometry:[25,-80 TO 26,-81]
lower-left corner as the start of the range and the upper-right corner as the end of the range.