Example usage for org.apache.lucene.spatial.prefix PrefixTreeStrategy getGrid

List of usage examples for org.apache.lucene.spatial.prefix PrefixTreeStrategy getGrid

Introduction

In this page you can find the example usage for org.apache.lucene.spatial.prefix PrefixTreeStrategy getGrid.

Prototype

public SpatialPrefixTree getGrid() 

Source Link

Usage

From source file:org.apache.solr.handler.component.SpatialHeatmapFacets.java

License:Apache License

/** Called by {@link org.apache.solr.request.SimpleFacets} to compute heatmap facets. */
public static NamedList<Object> getHeatmapForField(String fieldKey, String fieldName, ResponseBuilder rb,
        SolrParams params, DocSet docSet) throws IOException {
    //get the strategy from the field type
    final SchemaField schemaField = rb.req.getSchema().getField(fieldName);
    final FieldType type = schemaField.getType();
    if (!(type instanceof AbstractSpatialPrefixTreeFieldType)) {
        //FYI we support the term query one too but few people use that one
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                "heatmap field needs to be of type " + SpatialRecursivePrefixTreeFieldType.class);
    }//from   w ww  .j a  v a 2s .  c  o m
    AbstractSpatialPrefixTreeFieldType rptType = (AbstractSpatialPrefixTreeFieldType) type;
    final PrefixTreeStrategy strategy = (PrefixTreeStrategy) rptType.getStrategy(fieldName);
    final SpatialContext ctx = strategy.getSpatialContext();

    //get the bbox (query Rectangle)
    String geomStr = params.getFieldParam(fieldKey, FacetParams.FACET_HEATMAP_GEOM);
    final Shape boundsShape = geomStr == null ? ctx.getWorldBounds()
            : SpatialUtils.parseGeomSolrException(geomStr, ctx);

    //get the grid level (possibly indirectly via distErr or distErrPct)
    final int gridLevel;
    Integer gridLevelObj = params.getFieldInt(fieldKey, FacetParams.FACET_HEATMAP_LEVEL);
    final int maxGridLevel = strategy.getGrid().getMaxLevels();
    if (gridLevelObj != null) {
        gridLevel = gridLevelObj;
        if (gridLevel <= 0 || gridLevel > maxGridLevel) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                    FacetParams.FACET_HEATMAP_LEVEL + " should be > 0 and <= " + maxGridLevel);
        }
    } else {
        //SpatialArgs has utility methods to resolve a 'distErr' from optionally set distErr & distErrPct. Arguably that
        // should be refactored to feel less weird than using it like this.
        SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.Intersects/*ignored*/,
                boundsShape == null ? ctx.getWorldBounds() : boundsShape);
        final Double distErrObj = params.getFieldDouble(fieldKey, FacetParams.FACET_HEATMAP_DIST_ERR);
        if (distErrObj != null) {
            // convert distErr units based on configured units
            spatialArgs.setDistErr(distErrObj * rptType.getDistanceUnits().multiplierFromThisUnitToDegrees());
        }
        spatialArgs.setDistErrPct(params.getFieldDouble(fieldKey, FacetParams.FACET_HEATMAP_DIST_ERR_PCT));
        double distErr = spatialArgs.resolveDistErr(ctx, DEFAULT_DIST_ERR_PCT);
        if (distErr <= 0) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                    FacetParams.FACET_HEATMAP_DIST_ERR_PCT + " or " + FacetParams.FACET_HEATMAP_DIST_ERR
                            + " should be > 0 or instead provide " + FacetParams.FACET_HEATMAP_LEVEL + "="
                            + maxGridLevel + " if you insist on maximum detail");
        }
        //The SPT (grid) can lookup a grid level satisfying an error distance constraint
        gridLevel = strategy.getGrid().getLevelForDistance(distErr);
    }

    //Compute!
    final HeatmapFacetCounter.Heatmap heatmap;
    try {
        heatmap = HeatmapFacetCounter.calcFacets(strategy, rb.req.getSearcher().getTopReaderContext(),
                docSet.getTopFilter(), boundsShape, gridLevel,
                params.getFieldInt(fieldKey, FacetParams.FACET_HEATMAP_MAX_CELLS, 100_000) // will throw if exceeded
        );
    } catch (IllegalArgumentException e) {//e.g. too many cells
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e.toString(), e);
    }

    //Populate response
    NamedList<Object> result = new NamedList<>();
    result.add("gridLevel", gridLevel);
    result.add("columns", heatmap.columns);
    result.add("rows", heatmap.rows);
    result.add("minX", heatmap.region.getMinX());
    result.add("maxX", heatmap.region.getMaxX());
    result.add("minY", heatmap.region.getMinY());
    result.add("maxY", heatmap.region.getMaxY());

    boolean hasNonZero = false;
    for (int count : heatmap.counts) {
        if (count > 0) {
            hasNonZero = true;
            break;
        }
    }
    formatCountsAndAddToNL(fieldKey, rb, params, heatmap.columns, heatmap.rows,
            hasNonZero ? heatmap.counts : null, result);

    return result;
}

From source file:org.elasticsearch.index.mapper.geo.GeoShapeFieldMapperTests.java

License:Apache License

@Test
public void testDefaultConfiguration() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
            .startObject("location").field("type", "geo_shape").endObject().endObject().endObject().endObject()
            .string();/* w  w  w.  j a  va  2 s .  c  o m*/

    DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
    FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
    PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

    assertThat(strategy.getDistErrPct(), equalTo(GeoShapeFieldMapper.Defaults.DISTANCE_ERROR_PCT));
    assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
    assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoShapeFieldMapper.Defaults.GEOHASH_LEVELS));
}

From source file:org.elasticsearch.index.mapper.geo.GeoShapeFieldMapperTests.java

License:Apache License

@Test
public void testGeohashConfiguration() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
            .startObject("location").field("type", "geo_shape").field("tree", "geohash")
            .field("tree_levels", "4").field("distance_error_pct", "0.1").endObject().endObject().endObject()
            .endObject().string();//ww  w  .  j  a  v a2 s .c  o m

    DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
    FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
    PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

    assertThat(strategy.getDistErrPct(), equalTo(0.1));
    assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
    assertThat(strategy.getGrid().getMaxLevels(), equalTo(4));
}

From source file:org.elasticsearch.index.mapper.geo.GeoShapeFieldMapperTests.java

License:Apache License

@Test
public void testQuadtreeConfiguration() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
            .startObject("location").field("type", "geo_shape").field("tree", "quadtree")
            .field("tree_levels", "6").field("distance_error_pct", "0.5").endObject().endObject().endObject()
            .endObject().string();// w w  w  .  ja v  a 2 s .  co m

    DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
    FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
    PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

    assertThat(strategy.getDistErrPct(), equalTo(0.5));
    assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
    assertThat(strategy.getGrid().getMaxLevels(), equalTo(6));
}

From source file:org.elasticsearch.index.mapper.geo.GeoShapeFieldMapperTests.java

License:Apache License

@Test
public void testLevelPrecisionConfiguration() throws IOException {
    {//from   w w w  . j a  va  2s . c  o  m
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("tree_levels", "6").field("precision", "70m")
                .field("distance_error_pct", "0.5").endObject().endObject().endObject().endObject().string();

        DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
        FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        /* 70m is more precise so it wins */
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.quadTreeLevelsForPrecision(70d)));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "geohash").field("tree_levels", "6").field("precision", "70m")
                .field("distance_error_pct", "0.5").endObject().endObject().endObject().endObject().string();

        DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
        FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
        /* 70m is more precise so it wins */
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.geoHashLevelsForPrecision(70d)));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "geohash").field("tree_levels", GeoUtils.geoHashLevelsForPrecision(70d) + 1)
                .field("precision", "70m").field("distance_error_pct", "0.5").endObject().endObject()
                .endObject().endObject().string();

        DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
        FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.geoHashLevelsForPrecision(70d) + 1));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("tree_levels", GeoUtils.quadTreeLevelsForPrecision(70d) + 1)
                .field("precision", "70m").field("distance_error_pct", "0.5").endObject().endObject()
                .endObject().endObject().string();

        DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
        FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.quadTreeLevelsForPrecision(70d) + 1));
    }
}

From source file:org.elasticsearch.index.mapper.geo.GeoShapeFieldMapperTests.java

License:Apache License

@Test
public void testLevelDefaults() throws IOException {
    {/*from   w w  w  .  j  a v a 2s .  c o  m*/
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("distance_error_pct", "0.5").endObject().endObject()
                .endObject().endObject().string();

        DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
        FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        /* 50m is default */
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.quadTreeLevelsForPrecision(50d)));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "geohash").field("distance_error_pct", "0.5").endObject().endObject().endObject()
                .endObject().string();

        DocumentMapper defaultMapper = MapperTestUtils.newParser().parse(mapping);
        FieldMapper fieldMapper = defaultMapper.mappers().name("location").mapper();
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
        /* 50m is default */
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.geoHashLevelsForPrecision(50d)));
    }
}

From source file:org.elasticsearch.index.mapper.GeoShapeFieldMapperTests.java

License:Apache License

public void testDefaultConfiguration() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
            .startObject("location").field("type", "geo_shape").endObject().endObject().endObject().endObject()
            .string();/*from w ww  . jav a  2 s .  c  om*/

    DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1",
            new CompressedXContent(mapping));
    FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
    PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

    assertThat(strategy.getDistErrPct(), equalTo(0.025d));
    assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
    assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoShapeFieldMapper.Defaults.GEOHASH_LEVELS));
    assertThat(geoShapeFieldMapper.fieldType().orientation(),
            equalTo(GeoShapeFieldMapper.Defaults.ORIENTATION));
}

From source file:org.elasticsearch.index.mapper.GeoShapeFieldMapperTests.java

License:Apache License

public void testGeohashConfiguration() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
            .startObject("location").field("type", "geo_shape").field("tree", "geohash")
            .field("tree_levels", "4").field("distance_error_pct", "0.1").endObject().endObject().endObject()
            .endObject().string();//from   w ww .  jav  a 2s .  c  om

    DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1",
            new CompressedXContent(mapping));
    FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
    PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

    assertThat(strategy.getDistErrPct(), equalTo(0.1));
    assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
    assertThat(strategy.getGrid().getMaxLevels(), equalTo(4));
}

From source file:org.elasticsearch.index.mapper.GeoShapeFieldMapperTests.java

License:Apache License

public void testQuadtreeConfiguration() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
            .startObject("location").field("type", "geo_shape").field("tree", "quadtree")
            .field("tree_levels", "6").field("distance_error_pct", "0.5").field("points_only", true).endObject()
            .endObject().endObject().endObject().string();

    DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1",
            new CompressedXContent(mapping));
    FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
    assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

    GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
    PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

    assertThat(strategy.getDistErrPct(), equalTo(0.5));
    assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
    assertThat(strategy.getGrid().getMaxLevels(), equalTo(6));
    assertThat(strategy.isPointsOnly(), equalTo(true));
}

From source file:org.elasticsearch.index.mapper.GeoShapeFieldMapperTests.java

License:Apache License

public void testLevelPrecisionConfiguration() throws IOException {
    DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();

    {// w w w .j a  v  a  2 s .  c  om
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("tree_levels", "6").field("precision", "70m")
                .field("distance_error_pct", "0.5").endObject().endObject().endObject().endObject().string();

        DocumentMapper defaultMapper = parser.parse("type1", new CompressedXContent(mapping));
        FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        // 70m is more precise so it wins
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.quadTreeLevelsForPrecision(70d)));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("tree_levels", "26").field("precision", "70m").endObject()
                .endObject().endObject().endObject().string();

        DocumentMapper defaultMapper = parser.parse("type1", new CompressedXContent(mapping));
        FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

        // distance_error_pct was not specified so we expect the mapper to take the highest precision between "precision" and
        // "tree_levels" setting distErrPct to 0 to guarantee desired precision
        assertThat(strategy.getDistErrPct(), equalTo(0.0));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        // 70m is less precise so it loses
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(26));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "geohash").field("tree_levels", "6").field("precision", "70m")
                .field("distance_error_pct", "0.5").endObject().endObject().endObject().endObject().string();

        DocumentMapper defaultMapper = parser.parse("type1", new CompressedXContent(mapping));
        FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
        // 70m is more precise so it wins
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.geoHashLevelsForPrecision(70d)));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "geohash").field("tree_levels", GeoUtils.geoHashLevelsForPrecision(70d) + 1)
                .field("precision", "70m").field("distance_error_pct", "0.5").endObject().endObject()
                .endObject().endObject().string();

        DocumentMapper defaultMapper = parser.parse("type1", new CompressedXContent(mapping));
        FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(GeohashPrefixTree.class));
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.geoHashLevelsForPrecision(70d) + 1));
    }

    {
        String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
                .startObject("properties").startObject("location").field("type", "geo_shape")
                .field("tree", "quadtree").field("tree_levels", GeoUtils.quadTreeLevelsForPrecision(70d) + 1)
                .field("precision", "70m").field("distance_error_pct", "0.5").endObject().endObject()
                .endObject().endObject().string();

        DocumentMapper defaultMapper = parser.parse("type1", new CompressedXContent(mapping));
        FieldMapper fieldMapper = defaultMapper.mappers().getMapper("location");
        assertThat(fieldMapper, instanceOf(GeoShapeFieldMapper.class));

        GeoShapeFieldMapper geoShapeFieldMapper = (GeoShapeFieldMapper) fieldMapper;
        PrefixTreeStrategy strategy = geoShapeFieldMapper.fieldType().defaultStrategy();

        assertThat(strategy.getDistErrPct(), equalTo(0.5));
        assertThat(strategy.getGrid(), instanceOf(QuadPrefixTree.class));
        assertThat(strategy.getGrid().getMaxLevels(), equalTo(GeoUtils.quadTreeLevelsForPrecision(70d) + 1));
    }
}