我们有一个索引,其字段类型为GeoShape。如果我们进行的查询包含此字段,而该字段丢失,则会出现错误:
**Type: illegal_state_exception Reason: "Shape with name [34219995] found but missing geometry field"**
有什么方法可以为geoshape字段分配默认值,就像其他类型可能会为null的情况一样吗?
我们正在使用的查询是:(使用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”中的字段,则会收到错误消息。
答案 0 :(得分:0)
在字段的映射中添加"ignore_malformed": true
可以防止首先查询此类形状。请注意,尽管如此,您必须重新编制索引才能生效。
第二,尝试将ignore_unmapped
添加到您的GET geoindex/_search
{
"query": {
"geo_shape": {
"ignore_unmapped": true,
"polygon": {
"shape": {
"type": "point",
"coordinates": [
0.5,
0.5
]
},
"relation": "within"
}
}
}
}
查询中:
abstract class Enum<T> {
final T value;
const Enum(this.value);
}
class FlightScheduleStatus<int> extends Enum<int> {
const FlightScheduleStatus(int val) : super(val);
static const None = const FlightScheduleStatus(0);
static const OnTime = const FlightScheduleStatus(1);
static const Delayed = const FlightScheduleStatus(2);
}
Widget getFlightStates(LiveStatus liveStatus) {
switch (liveStatus.flightScheduleStatus) {
case FlightScheduleStatus.Delayed:
return Row(
children: <Widget>[
Text('Delayed'),
SizedBox(
width: 3,
),
Chip(
label: Text('${liveStatus.delayedTime}'),
backgroundColor: Colors.red,
),
],
);
break;
case FlightScheduleStatus.OnTime:
return Text('On Time');
break;
case FlightScheduleStatus.None:
return Text('N/A');
break;
}
}