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
    }
  }
}
相关推荐
lifewange15 分钟前
pytest-类中测试方法、多文件批量执行
开发语言·python·pytest
pluvium2737 分钟前
记对 xonsh shell 的使用, 脚本编写, 迁移及调优
linux·python·shell·xonsh
2401_827499991 小时前
python项目实战09-AI智能伴侣(ai_partner_5-6)
开发语言·python
PD我是你的真爱粉1 小时前
MCP 协议详解:从架构、工作流到 Python 技术栈落地
开发语言·python·架构
ZhengEnCi1 小时前
P2G-Python字符串方法完全指南-split、join、strip、replace的Python编程利器
python
是小蟹呀^1 小时前
【总结】LangChain中工具的使用
python·langchain·agent·tool
宝贝儿好1 小时前
【LLM】第二章:文本表示:词袋模型、小案例:基于文本的推荐系统(酒店推荐)
人工智能·python·深度学习·神经网络·自然语言处理·机器人·语音识别
王夏奇2 小时前
pythonUI界面弹窗设置的几种办法
python·ui
ZhengEnCi2 小时前
P2B-Python可迭代对象完全指南-从列表到生成器的Python编程利器
python
萌萌站起2 小时前
Vscode 中 python模块的导入问题
ide·vscode·python