ElasticSearch 简单的查询。查询存在该字段的资源,更新,统计

1.查询存在该字段的数据

{
  "query": {
    "bool": {
      "must": [
  
        {
          "exists": { 
            "field": "chainCode"
          }
        }
        
      ]
      ,
      "must_not": {
        "exists": {
          "field": "isDelete"
        }
      }
    }
  }
}

备注:存在chainCode 的字段并且不存在isDelete的资源

2.删除id(LxcAjXD2bS1)数据中的chainCode字段

{
    "query": {
        "term": {
            "id.keyword": "LxcAjXD2bS1"
        }
    },
    
   
    "script": {
        "source": "ctx._source.remove('chainCode')"
    }

}

3.查询es 中的条数

/hotel/_count
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "isDelete": {
              "value":  false
            }
          }
        }
      ]
    }
  }
}

4.查询map数据中存在某一个值的数据

code 的结构
"code": {
"108": "42981"
}

{
  "query":{

  "bool" : {
    "must" : [
      {
        "term" : {
          "code.108.keyword" : {
            "value" : "42921",
            "boost" : 1.0
          }
        }
      }
    ],
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }

  }
}

5.更新es 数据

{
    "query": {
        "term": {
            "id.keyword": "9988971080"
        }
    },
    
    "script": {
        "source": "ctx._source.code = params.code",
        "params": {
            "code": {
                "106": "9016003",
                "108": "9989719",
                "103": "H1460832"
            }
        }
    }
}

6.es 只返回某些具体的字段

{
  "_source": ["hotelName.value", "code.108", "address.value", "phone.value", "district.value", "priceUpdateTime"],
  "query": {
    "bool": {
      "must": [
        {
          "exists": {
            "field": "code.108"
          }
        }
      ]
    }
  },
  "sort": [
    {
      "priceUpdateTime": {
        "order": "desc"
      }
    }
  ],
  "size": 1000,  
  "from": 0
}

7.track_total_hits查询数据的条数

{
  "query": {
    "term": {
      "isDelete": true
    }
  },
  "track_total_hits": true
}

8.通过ID查询具体的某一条数据

{
    "query": {
        "term": {
            "id.keyword": "xZgr7KPlu"
        }
    }
}
相关推荐
m0_7482546624 分钟前
定时任务特辑 Quartz、xxl-job、elastic-job、Cron四个定时任务框架对比,和Spring Boot集成实战
java·spring boot·后端
海边漫步者39 分钟前
Idea2024中搭建JavaFX开发环境并创建运行项目
java·intellij-idea·javafx
Warren981 小时前
Springboot中分析SQL性能的两种方式
java·spring boot·后端·sql·mysql·intellij-idea
Distance失落心2 小时前
idea任意版本的安装
java·ide·java-ee·eclipse·intellij-idea
Aphelios3802 小时前
Linux 下 VIM 编辑器学习记录:从基础到进阶(下)
java·linux·学习·编辑器·vim
独孤求败Ace2 小时前
第46天:Web开发-JavaEE应用&原生和FastJson反序列化&URLDNS链&JDBC链&Gadget手搓
java·spring·java-ee
Ting-yu2 小时前
项目实战--网页五子棋(匹配模块)(4)
java
优人ovo2 小时前
3分钟idea接入deepseek
java·ide·intellij-idea
计算机学姐2 小时前
基于SpringBoot的校园消费点评管理系统
java·vue.js·spring boot·后端·mysql·spring·java-ee
猎人everest2 小时前
Spring Boot数据访问(JDBC)全解析:从基础配置到高级调优
java·spring boot·后端