NEST和Elasticsearch 7.7空几何

问题描述 投票:0回答:1

基于OGC简单要素标准,可以为ElasticShape字段类型使用默认值POLYGON(EMPTY)来获取Elasticsearch中的缺失值。

如果没有,如果没有任何值,如何为该字段提供一个空的Geometry。

elasticsearch nest
1个回答
0
投票

不支持POLYGON (EMPTY)。>>

您可以改为同步空值,然后使用倒置的exists查询对其进行查询:

PUT example
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_shape"
      }
    }
  }
}

POST example/_doc
{
  "location": "POLYGON ((100.0 0.0, 101.0 0.0, 101.0 1.0, 100.0 1.0, 100.0 0.0))"
}

POST example/_doc
{
  "location": null
}
GET example/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "exists": {
            "field": "location"
          }
        }
      ]
    }
  }
}

---或---

不过,您仍然可以利用ignore_malformed并同步POLYGON (EMPTY)

PUT example
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_shape",
        "ignore_malformed": true     <----
      }
    }
  }
}

POST example/_doc
{
  "location": "POLYGON ((100.0 0.0, 101.0 0.0, 101.0 1.0, 100.0 1.0, 100.0 0.0))"
}

POST example/_doc
{
  "location": "POLYGON (EMPTY)"
}

您仍然可以执行此操作:

GET example/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "exists": {
            "field": "location"
          }
        }
      ]
    }
  }
}

但是响应将更具特色:

{
  "_index":"example",
  "_type":"_doc",
  "_id":"Z-iPV3IBG_KW3EFnzAYA",
  "_score":0.0,
  "_ignored":[
    "location"
  ],
  "_source":{
    "location":"POLYGON (EMPTY)"
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.