Skip to content

排序查询


GET /user/_search
{
  "query": {
    "match": {
      "name": "李四"
    }
  },
  "sort": [
    {
      "age": {
        "order": "desc"
      }
    }
  ]
}
GET /user/_search
{
  "query": {
    "match": {
      "name": "李四"
    }
  },
  "sort": [
    {
      "age": {
        "order": "desc"
      }
    }
  ]
}

查询返回:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : "user",
        "_type" : "docs",
        "_id" : "4",
        "_score" : null,
        "_source" : {
          "name" : "李华",
          "sex" : 1,
          "age" : 26,
          "address" : "河北省"
        },
        "sort" : [
          26
        ]
      },
      {
        "_index" : "user",
        "_type" : "docs",
        "_id" : "2",
        "_score" : null,
        "_source" : {
          "name" : "李四",
          "sex" : 1,
          "age" : 25,
          "address" : "河北省"
        },
        "sort" : [
          25
        ]
      }
    ]
  }
}
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : "user",
        "_type" : "docs",
        "_id" : "4",
        "_score" : null,
        "_source" : {
          "name" : "李华",
          "sex" : 1,
          "age" : 26,
          "address" : "河北省"
        },
        "sort" : [
          26
        ]
      },
      {
        "_index" : "user",
        "_type" : "docs",
        "_id" : "2",
        "_score" : null,
        "_source" : {
          "name" : "李四",
          "sex" : 1,
          "age" : 25,
          "address" : "河北省"
        },
        "sort" : [
          25
        ]
      }
    ]
  }
}

备案号:冀ICP备20015584号-2