【发布时间】:2017-01-20 20:24:44
【问题描述】:
我有一个简单的 Trip 对象,其中包含许多 Departures,我想返回父 Trip,其中包含大于日期的任何离开。
旅行 JSON 看起来像
{
"title": "Something",
"code": "something else",
"departures" : [{ "out" : {date}, "in" : {date} }]
}
我可以通过使用发布数据在类型端点上调用 _search 手动使其在 PostMan 中工作:
{
"query" : {
"nested" : {
"path" : "departures",
"query" : {
"bool" : {
"filter" : [
{ "range" : { "departures.out" : { "gt" : 1483315200000 } } }
]
}
}
}
}
}
但是我使用的是 C#,特别是 NEST,并且这样编写了查询:
var searchResponse = client.Search<Trip>(s => s
.Index("indexName")
.From(0)
.Size(10)
.Query(q => q
.Nested(n => n
.Path(t => t.Departures)
.Query(q2 => q2
.Bool(b => b
.Must(f => f
.DateRange(dr => dr
.Field(t2 => t2.Departures.First().Out)
.GreaterThanOrEquals("01/02/2017")
.Format("dd/MM/yyyy")
)
)
)
)
)
)
);
NEST 抛出错误 Failed to create query:
query: {
"nested" : {
"query" : {
"bool" : {
"must" : [
{
"match_none" : {
"boost" : 1.0
}
}
],
"disable_coord" : false,
"adjust_pure_negative" : true,
"boost" : 1.0
}
},
"path" : "departures",
"ignore_unmapped" : false,
"score_mode" : "avg",
"boost" : 1.0
}
为什么不能正确创建日期范围查询?我尝试了各种不同的变体,但似乎没有任何效果!
【问题讨论】:
-
您为序列化查询发布的 json 与使用 NEST 的 fluent API 定义的查询不同。我刚刚尝试了您的示例并获得了预期的序列化查询。你的目标是什么版本的 Elasticsearch,你使用的是什么版本的 NEST?
-
在流利的 api 中,我将过滤器更改为 bool 内的必须,但如果我使用过滤器,我会得到相同的结果。您可以发布由 NEST 生成的查询吗?我用的是最新的。最近刚刚通过nuget安装了nest
-
您运行的是哪个版本的 Elasticsearch,您使用的是哪个版本的 NEST?
标签: c# .net elasticsearch nest