![](/img/trans.png)
[英]I worked on query of Elastic Search. But my result was not sorted by A to Z. So, how can I sort my result by A to Z
[英]In elastic how can I add sort to my query so that it returns the results in a sorted order
"query": {
"bool": {
"must":[
{
"range": {
"Date": {
"gte": firstDate,
"lte": lastDate
}
}
},
]
}
}
以上是我的查詢如何添加排序功能,以便我得到返回的值,因為它們現在沒有被返回排序
您可以使用排序搜索按一個或多個字段對結果進行排序。
例子:
{
"query": {
"bool": {
"must": [
{
"range": {
"Date": {
"gte": "firstDate",
"lte": "lastDate"
}
}
}
]
}
},
"sort": [
{
"firstDate": {
"order": "desc"
}
}
]
}
你可以插入一個排序子句
{
"sort": [
{
"Date": {
"format": "strict_date_optional_time_nanos",// From https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html
"order" : "desc"
}
}
],
"query": {
"bool": {
"must": [
{
"range": {
"Date": {
"gte": firstDate,
"lte": lastDate
}
}
}
]
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.