基于OGC简单要素标准,可以为ElasticShape字段类型使用默认值POLYGON(EMPTY)来获取Elasticsearch中的缺失值。
如果没有,如果没有任何值,如何为该字段提供一个空的Geometry。
不支持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)"
}
}