我有两个索引:
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"
}
}
]
}
与预定义地理形状的查询语法非常相似,但无济于事。我在文档中找不到任何内容。是否有解决此问题的方法,还是我必须管理副本?
答案 0 :(得分:1)
不幸的是,还没有办法(尚未)存储对索引形状的引用。您可以做的是将形状预索引到专用索引中,然后将这些形状的ID存储在profiles索引中的locations数组中,如下所示:
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"
最后,查询配置文件索引
POST profiles/_search
{
"query": {
"bool": {
"filter": [
{
...other profile criteria go here...
},
{
"terms": {
"locations": ["LOC1", "LOC3", "LOC4" ]
}
}
]
}
}
}