【弄nèng - Elasticsearch】DSL入门篇(十二)—— Exists Query 和 Sort排序

脚本查询,语法跟版本有关,我是用的es是5.2.2

1. Exists Query 判断字段是否存在

POST  schools/classes/_search
{
    "query": {
        "exists" : { "field" : "price" }
    }
}

查询存在price字段的记录

效果

{
  "took": 220,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "schools",
        "_type": "classes",
        "_id": "11",
        "_score": 1,
        "_source": {
          "classes_id": 11,
          "name": "班级11",
          "address": "深圳市福田区福华路11",
          "price": 11.4,
          "timestamp": 1572573660000,
          "users": [
            {
              "name": "SIMA",
              "age": "11",
              "price": 13.4
            },
            {
              "name": "LIYAO",
              "age": "13",
              "price": 13.2
            }
          ]
        }
      }
    ]
  }
}

2. Sort 排序

查询数据,简单处理后返回,如下地址+ “hello”

POST  schools/classes/_search
{
    "query": {
      
    },
    "sort": [
      {
        "timestamp": {
          "order": "desc"
        }
      }
    ]
}

效果

{
  "took": 143,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": null,
    "hits": [
      {
        "_index": "schools",
        "_type": "classes",
        "_id": "11",
        "_score": null,
        "_source": {
          "classes_id": 11,
          "name": "班级11",
          "address": "深圳市福田区福华路11",
          "price": 11.4,
          "timestamp": 1572573660000,
          "users": [
            {
              "name": "SIMA",
              "age": "11",
              "price": 13.4
            },
            {
              "name": "LIYAO",
              "age": "13",
              "price": 13.2
            }
          ]
        },
        "sort": [
          1572573660000
        ]
      }
    ]
  }
}

项目推荐

IT-CLOUD :IT服务管理平台,集成基础服务,中间件服务,监控告警服务等。
IT-CLOUD-ACTIVITI6 :Activiti教程源码。博文在本CSDN Activiti系列中。
IT-CLOUD-ELASTICSEARCH :elasticsearch教程源码。博文在本CSDN elasticsearch系列中。
IT-CLOUD-KAFKA :spring整合kafka教程源码。博文在本CSDN kafka系列中。
IT-CLOUD-KAFKA-CLIENT :kafka client教程源码。博文在本CSDN kafka系列中。

开源项目,持续更新中,喜欢请 Star~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值