我有以下在基巴纳州运行良好的情况:
{
"sort": [
{
"name.keyword": {
"order": "asc"
}
}
],
"query": {
"bool": {
"must": [],
"should": [],
"must_not": []
}
}
}
但是,我不确定如何在弹性客户端中使用该字符串的“排序”部分,我可以使用“原始”构建查询字符串,但是不确定如何对该排序进行操作>
答案 0 :(得分:0)
使用Elasticsearch .net client,嵌套,您可以通过以下方式轻松地将排序块添加到查询中:
s => s
.Sort(ss => ss
.Ascending(p => p.StartedOn)
.Descending(p => p.Name)
.Descending(SortSpecialField.Score)
.Ascending(SortSpecialField.DocumentIndexOrder)
.Field(f => f
.Field(p => p.Tags.First().Added)
.Order(SortOrder.Descending)
.MissingLast()
.UnmappedType(FieldType.Date)
.Mode(SortMode.Average)
.NestedPath(p => p.Tags)
.NestedFilter(q => q.MatchAll())
)
.Field(f => f
.Field(p => p.NumberOfCommits)
.Order(SortOrder.Descending)
.Missing(-1)
)
.GeoDistance(g => g
.Field(p => p.Location)
.DistanceType(GeoDistanceType.Arc)
.Order(SortOrder.Ascending)
.Unit(DistanceUnit.Centimeters)
.Mode(SortMode.Min)
.Points(new GeoLocation(70, -70), new GeoLocation(-12, 12))
)
.Script(sc => sc
.Type("number")
.Ascending()
.Script(script => script
.Source("doc['numberOfCommits'].value * params.factor")
.Params(p => p.Add("factor", 1.1))
)
)
)