【问题标题】:Elasticsearch Version 7.6 Errors when Missing Geoshape缺少 Geoshape 时的 Elasticsearch 版本 7.6 错误
【发布时间】:2020-05-02 19:54:35
【问题描述】:

我们有一个具有 GeoShape 类型字段的索引。如果我们进行包含此字段的查询,并且该字段丢失,我们会收到错误:

**Type: illegal_state_exception Reason: "Shape with name [34219995] found but missing geometry field"**

有什么方法可以为 geoshape 字段分配默认值,就像在其他类型可能为空的情况下一样?

我们使用的查询是这样的:(使用 NEST api):

filters.Add(fq => fq.Term(t => t.Field(f => f.LocalityId).Value(34219995)) || fq.GeoShape(g => g.Field("locationShape").Relation(GeoShapeRelation.Within).IndexedShape(f => f.Id(34219995).Index("GeoshapesIndex").Path("geometry")))); 

如果“GeoshapesIndex”中的字段丢失,我们会收到错误消息。

【问题讨论】:

    标签: elasticsearch nest


    【解决方案1】:

    "ignore_malformed": true 添加到您的字段映射应首先防止此类形状被查询。但请注意,您必须重新索引才能使其生效。

    其次,尝试将ignore_unmapped 添加到您的geo_shape 查询中:

    GET geoindex/_search
    {
      "query": {
        "geo_shape": {
          "ignore_unmapped": true,
          "polygon": {
            "shape": {
              "type": "point",
              "coordinates": [
                0.5,
                0.5
              ]
            },
            "relation": "within"
          }
        }
      }
    }
    

    【讨论】:

    • 感谢您的回复。不幸的是,两者都没有帮助。 ignore_unmapped 适用于没有映射的索引,但在我们的例子中,我们确实有一个映射,但值为 null。 ignore_malformed 也不起作用。任何其他想法。如果缺少 geoshape 字段,如何停止查询引发异常。一定有办法!
    • 地理查询前的bool.filter.exists呢? elastic.co/guide/en/elasticsearch/reference/current/…如果你分享了你的文档和映射,调试起来会更容易。
    • 不太熟悉 w/ 巢。这可能会有所帮助:stackoverflow.com/a/38537763/8160318
    猜你喜欢
    • 1970-01-01
    • 2020-09-10
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    • 2017-10-10
    相关资源
    最近更新 更多