ES13-查詢排序

1.按照文檔添加時間排序

elasticsearch默認查詢時按照文檔添加前後進行排序elasticsearch

GET telegraph/_search
{
  "query": {
    "match_all": {}
  }
}

2.根據相關度評分排序

GET telegraph/_search
{
  "query": {
    "match": {
      "title": "召開會議"
    }
  }
}

3.指定字段排序

按照發布時間倒序排序測試

GET telegraph/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "pubdate": {
        "order": "desc"
      }
    }
  ]
}

4.多字段排序

建立索引,添加測試數據spa

DELETE my_person

PUT  my_person

PUT my_person/my_index/1
{
  "name":"sean",
  "age":22,
  "salary":6000
}

PUT my_person/my_index/2
{
  "name":"sim",
  "age":20,
  "salary":5000
}

PUT my_person/my_index/3
{
  "name":"duck",
  "age":28,
  "salary":8000
}

PUT my_person/my_index/4
{
  "name":"lily",
  "age":20,
  "salary":4000
}

按照」age「倒序排序,當」age「相同時按照」salary「升序排序code

GET my_person/_search
{
  "sort": [
    {
      "age": {
        "order": "desc"
      }
    },
    {
      "salary": {
        "order": "asc"
      }
    }
  ]
}
相關文章
相關標籤/搜索