elasticsearch - 在 Elasticsearch 中使用预定义的 geo_shapes 创建文档
问题描述
我有两个索引:
- Profiles - 有一个字段,它是一个数组
geo_shape
- 位置 - 具有字段几何,它是
geo_shape
配置文件中的每个文档都有许多位置。目前,位置几何的副本存储在配置文件中。
是否可以通过创建预定义的配置文件来改善这一点geo_shapes
?我试过了
PUT profiles/profile/1
{
"locations": [
{
"indexed_shape": {
"id": "LOC1",
"index": "locations",
"path": "geometry",
"type": "location"
}
},
{
"indexed_shape": {
"id": "LOC2",
"index": "locations",
"path": "geometry",
"type": "location"
}
}
]
}
这很像预定义地理形状的查询语法,但无济于事。我在文档中找不到任何内容。这个问题有解决方案吗,还是我必须管理副本?
解决方案
不幸的是,(还)没有办法存储对索引形状的引用。您可以做的是将形状预先索引到专用索引中,然后将这些形状的 ID 存储在配置文件索引中的位置数组中,如下所示:
PUT shapes/doc/LOC1
{
... shape definition goes here ...
}
PUT shapes/doc/LOC2
{
... shape definition goes here ...
}
PUT profiles/doc/1
{
"locations": [ "LOC1", "LOC2" ]
... other fields
}
然后,当您需要查询时,您可以先对形状索引进行查询,收集匹配形状的 id,然后使用这些 id 查询配置文件索引。我没有办法让它比这更短。
首先,查询形状并收集 id:
POST shapes/_search?filter_path=hits.hits._id
{
"query" : {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
},
"relation": "within"
}
}
}
}
=> returns "LOC1", "LOC3", "LOC4"
最后查询profiles索引
POST profiles/_search
{
"query": {
"bool": {
"filter": [
{
...other profile criteria go here...
},
{
"terms": {
"locations": ["LOC1", "LOC3", "LOC4" ]
}
}
]
}
}
}
推荐阅读
- html - 为什么空块存在而空内联不存在?
- c# - VS 2019 中的 CreatePkgDef 异常
- file - LSH 是否适用于 zip、jar、wim、iso 或任何类型的压缩文件?
- django - 在没有表单的单个上传按钮 Django-rest 框架中上传多个图像
- python - while循环在python中没有正确执行
- excel-formula - 在 Excel 中使用 sumif 函数时的问题
- mount - mkdir 并挂载到 initramfs
- reactjs - 从 GitHub Pages 提供动态生成的文件
- c++ - 维护一个 unordered_map 但同时在每一步都需要它的最低映射值
- c++ - 特征命名访问向量段