ElasticSearch简称ES基础语法使用大全

目录

一、查

1.匹配查询

注意:字符串搜索时,会对输入的查询字符串进行分析和分词,可能导致意外匹配或未匹配。

bash 复制代码
#搜索
GET /your_index/_search
{
  "query": {
    "match": {
    "news_id" : 100
  }}
}

2. 精确匹配字符串

注意:term 查询日期字符串时,因为映射方式不同可能存在匹配不到

bash 复制代码
GET /your_index/_search
{
  "query": {
    "term": {
    "title.keyword" : "superman"
  }}
}

3.匹配某字段为空

bash 复制代码
GET /your_index/_search
{
  "query": {
    "term": {
    "name.keyword" : ""
  }}
}

二、改

1. 通过es_id修改内容

bash 复制代码
POST /your_index/_update/es_id
{"doc": {
  "new_id": "123",
  "name": "小明",
  "status": 1
}}

2. 匹配修改内容

bash 复制代码
POST /your_index/_update_by_query
{
  "script": {
    "source": "ctx._source.status = 1"
  },
  "query": {
    "match": {
    "status " : 2
  }}
}

二、增

1.添加单个文档

bash 复制代码
POST /your_index/_doc
{
  "name" : "yunxiao",
  "age" : 18
}

三、删

1.通过_id删除

bash 复制代码
DELETE /your_index/_doc/_id_123456

2.匹配删除

bash 复制代码
POST /your_index/_delete_by_query
{
  "query": {
    "match": {
      "status": 0
    }
  }
}
相关推荐
安_3 小时前
如何构建和使用向量索引?HNSW 和 IVF 有什么区别?
python·ai
小岐AI观3 小时前
智赋岐黄适合养生馆吗?
大数据·人工智能·物联网
大大大大晴天3 小时前
SR不只查内部表:External Catalog、联邦查询与统一分析
大数据
counting money4 小时前
Java IO流详解:从InputStream到文件操作实战
java·开发语言·python
坚持学习前端日记4 小时前
Python SQLAlchemy ORM 从0到1精通实战手册(基础到复杂高阶)
数据库·python·oracle
北斗落凡尘5 小时前
LangGraph 入门实战(11)--输出模式
后端·python·langchain
anxiao_m5 小时前
2026制造业云桌面选型攻略,不同生产场景适配方案汇总
大数据·网络·数据库
土星云SaturnCloud5 小时前
产线SOP动作级AI监管方案:土星云SE110S-WC8赋能合规识别、预警与效率分析
大数据·服务器·人工智能·ai·边缘计算
雪碧聊技术5 小时前
安装Python(保姆级教程)
python·版本更新·python下载
++==5 小时前
JSON和Python的 四种核心容器
python·json