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
    }
  }
}
相关推荐
TDengine (老段)1 小时前
TDengine IDMP 预测、异常检测与数据插补
大数据·数据库·人工智能·时序数据库·tdengine·涛思数据·idmp
kyle~2 小时前
FastAPI --- 将业务能力以 API 的形式提供给外部系统
python·fastapi·前后端
aiotto资源分享2 小时前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
Elasticsearch3 小时前
Java4Shell 远程代码执行漏洞 - CVE-2026-114938
elasticsearch
梯度下降者3 小时前
Python信号量,条件变量,事件学习
python·条件变量·事件·信号量·线程通信
MSTcheng.4 小时前
【AI应用实战】用 FastAPI + SSE 做一个自己的 AI 聊天网页:流式输出、多轮对话与完整源码
人工智能·python·大模型·fastapi·sse·ai聊天助手
字节跳动数据平台4 小时前
火山引擎 VeKnow 落地指南(上):从选场景到知识治理
大数据
the局外人4 小时前
Python 实战检索优化:BM25、向量与重排
数据库·后端·python
__underline__5 小时前
冷门Python知识点006篇:Python 类体里的名字,能被"凭空造出来"
后端·python
Elasticsearch5 小时前
哈利波特问答 Agent Builder + Workflow 教程
elasticsearch