Elasticsearch嵌套地理形状查询

时间:2018-08-27 23:15:55

标签: elasticsearch elasticsearch-geo-shape elasticsearch-nested

假设我有以下映射:

  "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”等,但是查询被忽略,返回整个索引。也许用这种类型的映射是不可能的?

很明显,我在这里错过了一些东西。有人可以帮我吗?任何帮助将不胜感激。

0 个答案:

没有答案