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"
      }
    }
  ]
}
相关文章
相关标签/搜索