如何同时使用 Elasticsearch 的 geo_point 和 geo_shape 类型?
How do I use Elasticsearch's geo_point and geo_shape types at the same time?
这是我们的文档:
{
"geometry" : {
"type" : "Point",
"coordinates" : [ -87.662682, 41.843014 ]
}
}
我们想使用 _geo_distance
排序进行 geo_shape
搜索,两者都针对相同的 geometry
字段。前者需要geo_shape
类型而后者需要geo_point
.
这两个 索引单独成功,但不一起:
"geometry": {
"type": "geo_shape"
}
和
"geometry": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
},
到目前为止我们已经尝试了这些并且失败了:
"geometry": {
"type": "geo_shape"
},
"geometry.coordinates": {
"type": "geo_point"
},
还有
"geometry": {
"copy_to": "geometryShape",
"type": "geo_shape"
},
"geometryShape": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
}
还有
"geometry": {
"copy_to": "geometryShape",
"properties": {
"coordinates": {
"type": "geo_point"
}
}
},
"geometryShape": {
"type": "geo_shape"
}
关于如何正确创建这个索引有什么想法吗?
我会选择 function_score_query and your original mapping with just the geo_shape. Elasticsearch docs suggest that scoring by distance 通常比按距离排序更好。
另外请注意,您是否使用 geo_bounding_box 和 geo_point 结帐?我不确定您将 geo_shape 类型用于什么目的,但您可以使用边界框复制它。查看示例 here.
如果启用了脚本,那么您可以通过在映射
中指定transforms来实现它
会在这些行上看到一些东西:
put test/test_type/_mapping
{
"transform": {
"script": "if (ctx._source['geometry']['coordinates']) ctx._source['test'] = ctx._source['geometry']['coordinates']",
"lang": "groovy"
},
"properties": {
"geometry": {
"type": "geo_shape"
},
"coordinates": {
"type": "geo_point"
}
}
}
这是我们的文档:
{
"geometry" : {
"type" : "Point",
"coordinates" : [ -87.662682, 41.843014 ]
}
}
我们想使用 _geo_distance
排序进行 geo_shape
搜索,两者都针对相同的 geometry
字段。前者需要geo_shape
类型而后者需要geo_point
.
这两个 索引单独成功,但不一起:
"geometry": {
"type": "geo_shape"
}
和
"geometry": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
},
到目前为止我们已经尝试了这些并且失败了:
"geometry": {
"type": "geo_shape"
},
"geometry.coordinates": {
"type": "geo_point"
},
还有
"geometry": {
"copy_to": "geometryShape",
"type": "geo_shape"
},
"geometryShape": {
"properties": {
"coordinates": {
"type": "geo_point"
}
}
}
还有
"geometry": {
"copy_to": "geometryShape",
"properties": {
"coordinates": {
"type": "geo_point"
}
}
},
"geometryShape": {
"type": "geo_shape"
}
关于如何正确创建这个索引有什么想法吗?
我会选择 function_score_query and your original mapping with just the geo_shape. Elasticsearch docs suggest that scoring by distance 通常比按距离排序更好。
另外请注意,您是否使用 geo_bounding_box 和 geo_point 结帐?我不确定您将 geo_shape 类型用于什么目的,但您可以使用边界框复制它。查看示例 here.
如果启用了脚本,那么您可以通过在映射
中指定transforms来实现它会在这些行上看到一些东西:
put test/test_type/_mapping
{
"transform": {
"script": "if (ctx._source['geometry']['coordinates']) ctx._source['test'] = ctx._source['geometry']['coordinates']",
"lang": "groovy"
},
"properties": {
"geometry": {
"type": "geo_shape"
},
"coordinates": {
"type": "geo_point"
}
}
}