我正在使用NEST查询ELasticsearch数据库,以获取在Leaflet地图上的UI上绘制的某些GeoShape中的数据。 我用于执行此查询的服务器端代码如下:
注意: geoJsonFeature 是GeoJson从UI发送到服务器的功能。它是下面代码中所示的 Feature 类类型。
public class Feature
{
public string type { get; set; }
public Properties properties { get; set; }
public Geometry geometry { get; set; }
}
var geometry = geoJsonFeature.geometry;
var type = geometry.type;
var coords = geometry.coordinates[0].Select(shapeArr =>
{
double lon = shapeArr[0];
double lat = shapeArr[1];
return new GeoCoordinate(lat, lon);
});
var polygon = new PolygonGeoShape(
new[]
{
coords
});
var result = dbClient.Search<MediaSummary>(s => s
.Index("mediasummary")
.Type(typeof(MediaSummary))
.Query(q =>
q.GeoShapePolygon(c => c
.Name("geoShape_query")
.Boost(1.1)
.Field(p => p.location)
.Coordinates(polygon.Coordinates)
.Relation(GeoShapeRelation.Intersects)
.IgnoreUnmapped(true)
)));
var count = result.Total;
var list= result.Documents.ToList();
无论我在地图上绘制多大的多边形,列表始终为空。 我猜我的服务器端逻辑有问题。
有人可以指导需要做什么吗?
更新:有人请求索引映射和DebugInformation。这些是
媒体摘要的索引映射
{
"mediasummary" : {
"aliases" : { },
"mappings" : {
"media" : {
"properties" : {
"@timestamp" : {
"type" : "date"
},
"ClientID" : {
"type" : "integer"
},
"ClientStatus" : {
"type" : "integer"
},
"Duration" : {
"type" : "long"
},
"EndDate" : {
"type" : "date"
},
"FileSize" : {
"type" : "long"
},
"FileType" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"IsRestrictedView" : {
"type" : "boolean"
},
"MediaState" : {
"type" : "integer"
},
"MediaStatus" : {
"type" : "integer"
},
"properties" : {
"lat" : {
"type" : "float"
},
"logTime" : {
"type" : "date"
},
"lon" : {
"type" : "float"
},
"sensorEventId" : {
"type" : "long"
}
}
},
"StartDate" : {
"type" : "date"
},
"StationID" : {
"type" : "integer"
},
"UnitID" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"UserID" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"VideoID" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"location" : {
"type" : "geo_point"
}
}
}
},
"settings" : {
"index" : {
"refresh_interval" : "5s",
"number_of_shards" : "3",
"provided_name" : "mediasummary",
"creation_date" : "1548853211953",
"number_of_replicas" : "1",
"uuid" : "lwHHKK89RzuGn_LZ6DW4Nw",
"version" : {
"created" : "6050499"
}
}
}
}
}
DebugInformation
Unsuccessful low level call on POST: /mediasummary/media/_search?typed_keys=true
# Audit trail of this API call:
- [1] PingSuccess: Node: http://localhost:9200/ Took: 00:00:00.0599653
- [2] BadResponse: Node: http://localhost:9200/ Took: 00:00:01.2732751
# OriginalException: Elasticsearch.Net.ElasticsearchClientException: The remote server returned an error: (400) Bad Request.. Call: Status code 400 from: POST /mediasummary/media/_search?typed_keys=true. ServerError: Type: search_phase_execution_exception Reason: "all shards failed" ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.
at System.Net.HttpWebRequest.GetResponse()
at Elasticsearch.Net.HttpWebRequestConnection.Request[TResponse](RequestData requestData)
--- End of inner exception stack trace ---
# Request:
{"query":{"geo_shape":{"_name":"geoShape_query","ignore_unmapped":true,"location":{"relation":"intersects","shape":{"type":"polygon","coordinates":[[[66.995573,24.883649],[66.995573,24.883649],[66.979094,24.860911],[66.979094,24.860911],[67.004499,24.823369],[67.004499,24.823369],[67.024584,24.830691],[67.024584,24.830691],[67.074881,24.853746],[67.074881,24.853746],[67.04484,24.8796],[67.04484,24.8796],[67.027845,24.892525],[67.027845,24.892525],[66.995573,24.883649]]]}}}}}
# Response:
{"error":{"root_cause":[{"type":"query_shard_exception","reason":"Field [location] is not of type [geo_shape] but of type [geo_point]","index_uuid":"lwHHKK89RzuGn_LZ6DW4Nw","index":"mediasummary"}
注意:“位置”字段的代码中存在区分大小写的问题,即POCO类的名称类似于“位置”而不是“位置”。我已修复此问题,现在在其映射和DebugInformation上方进行介绍。
现在清楚地表明该错误是由于以下原因:
Field [location] is not of type [geo_shape] but of type [geo_point]"
但是我现在不明白下一步该怎么做?