具有地理边界框查询的Elasticsearch多索引查询

时间:2016-08-21 09:07:15

标签: elasticsearch

Elasticsearch使您能够查询这些索引上存在与否的字段上的多个索引。

但是当使用geo_bounding_box弹性查询多个索引时,如果所查询的字段在所有请求的索引中不存在,则抛出异常。

似乎弹性检查是否将所需字段映射为地理点。

有没有办法在不编辑映射的情况下实现此查询并在所有凹槽中添加所有geo_filed?

1 个答案:

答案 0 :(得分:1)

您可以使用bool/should安排中的indices query,如下所示。这样,您就不会冒险使用错误的字段名称查询索引:

POST /indexA,indexB/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "indices": {
            "indices": [
              "indexA"
            ],
            "query": {
              "geo_bounding_box": {
                "x_location": {...}              }
            }
          }
        },
        {
          "indices": {
            "indices": [
              "indexB"
            ],
            "query": {
              "geo_bounding_box": {
                "y_location": {...}
              }
            }
          }
        }
      ]
    }
  }
}
相关问题