- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用elasticsearch-dsl-drf,我只是将文档上的单个location
字段转换为具有以下定义的NestedField
:location = fields.NestedField(properties={"point": fields.GeoPointField()})
然后在我看来(我添加了path
并更改了field
值以使其正常工作):
geo_spatial_filter_fields = {
'location': {
'path': 'location',
'field': 'point',
'lookups': [constants.LOOKUP_FILTER_GEO_DISTANCE]
}
}
geo_spatial_ordering_fields = {'location': None}
{
"query":{
"nested":{
"path":"location",
"query":{
"geo_distance":{
"distance":"16090km",
"location.point":{
"lat":"52.240995",
"lon":"0.751156"
},
"distance_type":"arc"
}
}
}
},
"sort":[
{
"_geo_distance":{
"location.point":{
"lat":"52.240995",
"lon":"0.751156"
},
"unit":"km",
"distance_type":"plane",
"order":"asc"
}
},
{
"date_first_registered":{
"order":"desc"
}
}
]
}
def attach_nested_path_to_queryset(queryset: Search):
"""
Attach nested path to the query and sort keys in the queryset
and update the queryset using `update_from_dict`
**The updating is done by reference**
:param queryset: the original queryset
:type queryset: Search
:return:
"""
queryset_dict = queryset.to_dict()
attach_nested_path_to_query(queryset_dict)
attach_nested_path_to_sort(queryset_dict)
# update queryset
queryset.update_from_dict(queryset_dict)
def attach_nested_path_to_query(queryset_dict: dict):
"""
Looks for geo_distance in the queryset dict, if it's at the top level
we modify the top level query, meaning that there's only one query, otherwise
we loop over the list of `must` queries and try to find `geo_distance`
**The updating is done by reference**
:param queryset_dict: the queryset in dict format
:type queryset_dict: dict
:return:
"""
query = queryset_dict["query"]
if "geo_distance" in query:
queryset_dict["query"] = {"nested": {"path": "location", "query": query}}
elif "bool" in query and "must" in query["bool"]:
for index, must_query in enumerate(query["bool"]["must"]):
if "geo_distance" in must_query:
queryset_dict["query"]["bool"]["must"][index] = {"nested": {"path": "location", "query": must_query}}
break
def attach_nested_path_to_sort(queryset_dict: dict):
"""
This function loops over the `sort` queries, and
looks for `_geo_distance` in order to add the `nested_path` key/value
**The updating is done by reference**
:param queryset_dict: the queryset in dict format
:type queryset_dict: dict
:return:
"""
sort = queryset_dict["sort"]
if isinstance(sort, list):
for index, sorting in enumerate(sort):
if "_geo_distance" in sorting:
queryset_dict["sort"][index]["_geo_distance"]["nested_path"] = "location"
最佳答案
在地理位置距离排序中包括"nested_path": "location"
:
{
"query":{
"nested":{
"path":"location",
"query":{
"geo_distance":{
"distance":"16090km",
"location.point":{
"lat":52.240995,
"lon":0.751156
},
"distance_type":"arc"
}
}
}
},
"sort":[
{
"_geo_distance":{
"nested_path": "location",
"location.point":{
"lat":52.240995,
"lon":0.751156
},
"unit":"km",
"distance_type":"plane",
"order":"asc"
}
},
{
"date_first_registered":{
"order":"desc"
}
}
]
}
关于python-3.x - 包含GeoPoint的位置列表-(geo_spatial_filter_fields,geo_distance),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62434187/
我正在尝试使用 elasticsearch 进行按邻近度排序的搜索。我安装了 FOSElasticaBundle 并且在我的 config.yml 中有这个配置: fos_elastica:
我无法让我的过滤器查询与 geo_distance 一起正常工作。它似乎返回 0 次点击。但是,如果我不尝试查找地理位置,我的所有其他查询都有效。 我正在使用 2.3.1 版的 ElasticSear
我正在使用elasticsearch-dsl-drf,我只是将文档上的单个location字段转换为具有以下定义的NestedField: location = fields.NestedField(
我在nodejs应用程序中使用elasticsearch模块,以便通过geo_points查找文档。 根据http://www.elastic.co/guide/en/elasticsearch/cl
点击 { "_index" : "users", "_type" : "user", "_id" : "001", "_score" : 1, "_source
我想运行一个 elasticsearch 查询来查找给定点 10 英里内的项目。 我知道如何用帖子来做,但我想对 uri 中的所有内容使用 get。 我找到了下面的例子,但它不起作用。 http://
我有地理对象的 Elasticsearch 数据库。我想在自定义距离内搜索一些 geo_point 周围最近的对象,然后将它们显示在谷歌地图上。使用默认的 elasticsearch 过滤器 - ge
我是一名优秀的程序员,十分优秀!