elasticsearch - Elasticsearch 嵌套地理形状查询
问题描述
假设我有以下映射:
"mappings": {
"doc": {
"properties": {
"name": {
"type": "text"
},
"location": {
"type": "nested",
"properties": {
"point": {
"type": "geo_shape"
}
}
}
}
}
}
}
索引中有一个文档:
POST /example/doc?refresh
{
"name": "Wind & Wetter, Berlin, Germany",
"location": {
"type": "point",
"coordinates": [13.400544, 52.530286]
}
}
如何进行嵌套地理形状查询?文档中常见的地理形状查询示例(可以跳过“bool”块):
{
"query":{
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
},
"relation": "within"
}
}
}
}
}
}
嵌套查询的示例是:
{
"query": {
"nested" : {
"path" : "obj1",
"score_mode" : "avg",
"query" : {
"bool" : {
"must" : [
{ "match" : {"obj1.name" : "blue"} },
{ "range" : {"obj1.count" : {"gt" : 5}} }
]
}
}
}
}
}
现在如何组合它们?在文档中提到嵌套过滤器已被嵌套查询替换。它表现为“查询上下文”中的查询和“过滤上下文”中的过滤器。
如果我尝试查询与该点相交:
{
"query": {
"nested": {
"path": "location",
"query": {
"geo_shape": {
"location.point": {
"shape": {
"type": "point",
"coordinates": [
13.400544,
52.530286
]
},
"relation": "disjoint"
}
}
}
}
}
}
即使关系“不相交”,我仍然会取回文档,所以它不正确。我尝试了不同的组合,使用“bool”和“filter”等,但查询被忽略,返回整个索引。也许这种类型的映射是不可能的?
显然我在这里遗漏了一些东西。有人可以帮我解决这个问题吗?任何帮助是极大的赞赏。
解决方案
推荐阅读
- heroku - 部署 heroku Strapi 应用程序有什么问题
- ios - 通过 NSKeyValueObservation 观察到的 AVPlayer 值始终为零
- lotus-notes - 将鼠标悬停在 Action Hot-Spot Notes 客户端上的文本上
- shell - 如何知道我的计算机中是否安装了 Dart 或 Flutter?
- ms-access - 无法将访问表单链接到数据集
- r - 根据 R 中的两个布尔列值将值保留在列的单行中
- vue.js - 如何提取系统字体并实现为下拉菜单以更改网页上文本的字体?
- python - Scrapy 蜘蛛从文本文件中的 URL 列表中抓取最后一个 URL
- javascript - 通过其他数组中的元素过滤数组对象
- sql - 使用返回 int 的函数时出现问题