【问题标题】:Create index with geoshape property mapping使用 geoshape 属性映射创建索引
【发布时间】:2014-09-05 08:40:22
【问题描述】:

我正在使用 Elasticsearch 的 NEST 客户端库为特定类型创建索引。

该类型包含三个string 属性加上一个用于保存geo_shape 类型(特别是用于envelope 形状)。

问题是,生成的请求在 ES 中解析失败:

{
   "error": "MapperParsingException[mapping [layer]]; nested: MapperParsingException[No handler for type [point] declared on field [boundingBox]]; ",
   "status": 400
}

生成此错误消息的 NEST 构建的请求是:

POST /metadata
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "layer": {
      "_all": {
        "enabled": false
      },
      "properties": {
        "namespace": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "abstract": {
          "type": "string"
        },
        "boundingBox": {
          "type": "point",
          "tree": "geohash",
          "tree_levels": 2,
          "distance_error_pct": 0.025
        }
      }
    }
  }
}

我发现唯一阻止此请求成功的是boundingBox 属性的type 声明,它的值应该是geo_shape 而不是point。

这里是用于执行调用的 C# 代码:

ElasticClient client = new ElasticClient(settings);

IIndicesOperationResponse response = client.CreateIndex(c => c
    .Index("metadata")
    .NumberOfShards(1)
    .NumberOfReplicas(0)
    .AddMapping<ESLayer>(m => m
        .Type("layer")
        .AllField(a => a.Enabled(false))
        .Properties(p => p
        .String(x => x.Name(n => n.Namespace))
        .String(x => x.Name(n => n.Name))
        .String(x => x.Name(n => n.Abstract))
        .GeoShape(x => x
            .Name(n => n.BoundingBox)
            .Tree(GeoTree.Geohash)
            .TreeLevels(2)
            .DistanceErrorPercentage(0.025)))));

还有ESLayer 类:

private class ESLayer
{
    public string Namespace { get; set; }

    public string Name { get; set; }

    public string Abstract { get; set; }

    public EnvelopeGeoShape BoundingBox { get; set; }
}

请注意,我使用 NEST 附带的 EnvelopeGeoShape 类来表示边界框属性。

Elasticsearch 版本:1.3.1

NEST 版本:1.0.2

关于我可能遗漏什么的任何线索?

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    这肯定是一个错误;不错的收获。我刚刚为此打开了问题#925 并推送了一个修复程序。它将包含在我们计划很快推出的下一个版本 (1.1.0) 中。同时,您可以在此处从我们的 CI 构建中获取 NuGet 包:https://www.myget.org/gallery/elasticsearch-net。

    【讨论】:

    • 谢谢@Greg,很高兴听到这个消息!我会在下一个版本发布后立即切换。与此同时,我想测试夜间构建,但 myget 现在似乎已关闭。该软件包的任何其他来源?
    • Myget 似乎工作正常,至少对我来说是这样。唯一的其他选择是克隆 GitHub 存储库并编译解决方案。
    • 我已经尝试编译源代码并且成功了。今天也尝试访问 myget,它现在为我工作。干杯!
    【解决方案2】:

    ES 中没有点的类型。您应该根据您的要求使用“geo_point”或“geo_shape”。

    见: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-geo-point-type.html

    还有: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html

    编辑:您使用的映射选项适用于 geo_shape 类型

    【讨论】:

    • 谢谢,我意识到了。但我不是手动向 ES 写入请求,而是通过 NEST 库。我的问题更多是关于用于创建索引的 .NET 代码,如果它缺少某些东西,或者我正面临 NEST 错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-23
    • 2018-06-10
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多