es常用查询编辑

复制代码
查询指定id信息
GET /index_name/_doc/1074266245


查询指定信息并降序
GET /index_name/_search
{
  "query": {
    "term": {
      "deviceId": {
        "value": "1074266245"
      }
    }
  }, 
  "sort": [
    {
      "timestamp": {
        "order": "desc"
      }
    }
  ]
}



//多条件查询
GET /index_name/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "payload.locator_dev_id": {
              "value": 100902
            }
          }
        },
        {
          "term": {
            "payload.dev_id": {
              "value": 100301
            }
          }
        }
      ]
    }
  },
  "sort": [
    {
      "timestamp": {
        "order": "desc"
      }
    }
  ]
}
//自定字段去重查询
GET /index_name/_search
{
    "query": {
    "term": {
      "bodyObj.payLoad.dev_id": {
        "value": "100101"
      }
    }
    },
    "collapse": {
        "field": "bodyObj.payLoad.key"
    },
    "from": 0,
    "size": 10,
    "track_total_hits": true,
    "aggs": {
      "courseAgg": {
        "cardinality": {
          "field": "bodyObj.payLoad.key"
        }
      }
    }
}
//修改指定字段值
POST /index_name/_update/101202
{
  "doc": {
    "category":"2"
  }
}

#指定字段必须存在或不存在
GET /index_name/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "exists": {
            "field": "deviceId"
          }
        }
      ]
    }
  },
  "sort": [
    {
      "timestamp": {
        "order": "desc"
      }
    }
  ]
}
相关推荐
xieliyu.2 小时前
Java算法精讲:双指针(三)
java·开发语言·算法
明夜之约2 小时前
Spring Boot 自动装配源码
java·spring boot·后端
Leaton Lee2 小时前
Spring Boot分层架构详解:从Controller到Service再到Mapper的完整流程
java·spring boot·后端·架构
Jinkxs2 小时前
Resilience4j- 与 Spring Boot 快速集成:自动配置与基础注解使用
java·spring boot·后端
辣机小司2 小时前
【踩坑记录:Spring Boot 配置文件读取值不一致?警惕 YAML 的“八进制陷阱”与 SnakeYAML 版本之谜】
java·spring boot·后端·yaml·踩坑记录
fangdengfu1233 小时前
ES分析系统各个服务日志占用量
java·前端·elasticsearch
云烟成雨TD3 小时前
Spring AI 1.x 系列【51】可观测性技术选型
java·人工智能·spring
星越华夏3 小时前
ESP32-CAM图像传输项目说明文档
java·后端·struts·esp32
Jinkxs4 小时前
Java 跨域14-Java 与区块链(Hyperledger)集成
java·开发语言·区块链
晨曦中的暮雨5 小时前
Golang速通(Javaer版)
java·开发语言·后端·golang