Elasticsearch 2.3 Geo Shape类型映射

时间:2016-10-28 11:14:59

标签: elasticsearch geospatial quadtree

我在Elasticsearch索引中有一个字段,其中包含以下映射

   "cluster_boundary": {
        "type": "geo_shape",
        "tree": "quadtree",
        "precision": "1mm"
    }

但是当我将此映射放在elasticsearch索引中时,我收到以下错误

java.lang.IllegalArgumentException: maxLevels of 36 exceeds limit of 29
     at org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree.<init>(PackedQuadPrefixTree.java:70)
     at org.elasticsearch.index.mapper.geo.GeoShapeFieldMapper$GeoShapeFieldType.freeze(GeoShapeFieldMapper.java:276)
     at org.elasticsearch.index.mapper.FieldMapper.<init>(FieldMapper.java:289)
     at org.elasticsearch.index.mapper.geo.GeoShapeFieldMapper.<init>(GeoShapeFieldMapper.java:428)
     at org.elasticsearch.index.mapper.geo.GeoShapeFieldMapper$Builder.build(GeoShapeFieldMapper.java:160)
     at org.elasticsearch.index.mapper.geo.GeoShapeFieldMapper$Builder.build(GeoShapeFieldMapper.java:119)
     at org.elasticsearch.index.mapper.object.ObjectMapper$Builder.build(ObjectMapper.java:167)
     at org.elasticsearch.index.mapper.DocumentMapper$Builder.<init>(DocumentMapper.java:88)
     at org.elasticsearch.index.mapper.MapperBuilders.doc(MapperBuilders.java:44)
     at org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:118)
     at org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:99)
     at org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:498)
     at org.elasticsearch.cluster.metadata.MetaDataMappingService$PutMappingExecutor.applyRequest(MetaDataMappingService.java:257)
     at org.elasticsearch.cluster.metadata.MetaDataMappingService$PutMappingExecutor.execute(MetaDataMappingService.java:230)
     at org.elasticsearch.cluster.service.InternalClusterService.runTasksForExecutor(InternalClusterService.java:468)
     at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:772)
     at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:231)
     at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:194)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
     at java.lang.Thread.run(Thread.java:745)

如果我将quadtree更改为geohash则可行。而且,根据elasticsearch,quadtree中允许的最大树级别为50

1 个答案:

答案 0 :(得分:2)

PackedQuadPrefixTree的最高级别为29,而QuadPrefixTree的最高级别为50.您可以检查herehere

我浏览了ES source codequadtree映射到lucene PackedQuadPrefixTree,因此您必须将精度值降低到1m,转换为26个tree_levels,或者您可以使用最多50个级别的legacyquadtree

如果您使用out of memory error指定非常多的级别而不是说最大允许级别为50,那么我注意到的一件事是ES抛出legacyquadtree

PUT test_index/_mapping/test_type
{
  "properties": {
    "test": {
      "type": "geo_shape",
      "tree": "legacyquadtree",
      "tree_levels": "54354552"
    }
  }
}

理想情况下,上面的代码应该说最大级别是50,但是它会耗尽堆空间并抛出OOM错误。

我也认为1mm太精确了,即使使用leagcyquadtree也会占用大量内存。 More就此而言。我还在github上打开了一个issue,您可以关注它。