【发布时间】:2018-06-22 04:10:22
【问题描述】:
我正在尝试构建一个嵌套查询,该查询需要按嵌套对象上的多个术语进行过滤。我正在使用 Nest nuget 包版本 6.1
查询是使用 Nest DSL 语法构建的,如下所示:
queryContainer &= Query<PropertyDTO>.Nested(n => n
.Path(p => p.Publications)
.Query(q =>
q.Term(t => t
.Field(ff => ff.Publications.First().Id == publicationId.ToString(CultureInfo.InvariantCulture))
)
&& q.DateRange(r =>
r
.Field(f => f.Publications.First().PublishedOn)
.GreaterThanOrEquals(
from.HasValue
? DateMath.Anchored(from.Value)
: DateMath.Anchored(DateTime.MinValue)
)
.LessThanOrEquals(
to.HasValue
? DateMath.Anchored(to.Value)
: DateMath.Anchored(DateTime.Now)
)
)
)
);
预期的结果应该是:
{
"nested": {
"query":
{
"bool": {
"must": [
{
"range": {
"publications.publishedOn": {
"gte": "2018-06-13T00:00:00",
"lte": "2018-06-20T23:59:59"
}
}
},
{
"term": {
"publications.id": {
"value": "1.510136"
}
}
}
]
}
},
"path": "publications"
}
}
但相反,我得到:
{
"nested": {
"query": {
"term": {
"publications.id": {
"value": "1.510136"
}
}
},
"path": "publications"
}
},
{
"nested": {
"query": {
"range": {
"publications.publishedOn": {
"gte": "2018-06-14T00:00:00",
"lte": "2018-06-21T23:59:59"
}
}
},
"path": "publications"
}
}
我做错了什么?
目前我正在使用基于原始查询版本的解决方法,但我想使用更易于重构的 Nest DSL 语法。
【问题讨论】:
标签: c# elasticsearch nest