使用geoshape属性映射创建索引

时间:2014-09-04 21:21:07

标签: c# elasticsearch nest

我正在使用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
        }
      }
    }
  }
}

我发现保持此请求成功的唯一方法是type属性的boundingBox声明,其值应为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

我可能遗失的任何线索?

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

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类型