spring boot 项目中搭建 ElasticSearch 中间件 一 postman 操作 es

postman 操作 es

      • [1. 简介](#1. 简介)
      • [2. 环境](#2. 环境)
      • [3. postman操作索引](#3. postman操作索引)
        • [3.1 创建索引](#3.1 创建索引)
        • [3.2 查看索引](#3.2 查看索引)
        • [3.3 查看所有索引](#3.3 查看所有索引)
        • [3.4 删除索引](#3.4 删除索引)
      • [4. postman操作文档](#4. postman操作文档)
        • [4.1 添加文档](#4.1 添加文档)
        • [4.2 查询文档](#4.2 查询文档)
        • [4.3 查询全部文档](#4.3 查询全部文档)
        • [4.4 更新文档](#4.4 更新文档)
        • [4.5 局部更新文档](#4.5 局部更新文档)
        • [4.6 删除文档](#4.6 删除文档)
        • [4.7 条件查询文档1](#4.7 条件查询文档1)
        • [4.8 条件查询文档2](#4.8 条件查询文档2)
        • [4.9 条件查询文档 limit](#4.9 条件查询文档 limit)
        • [4.10 条件查询文档 less](#4.10 条件查询文档 less)

本文是ElasticSearch 的入门文章,包含ElasticSearch 的环境准备和基础操作(使用postman)
ElasticSearch 系列文章目的是使用ElasticSearch结合spring boot项目实现项目的搜索功能。
系列文章 :

spring boot 项目中搭建 ElasticSearch 中间件 二 java api 操作 es
spring boot 项目中搭建 ElasticSearch 中间件 三 spring data 操作 es

1. 简介

存储,检索数据

集群扩展

PB级处理数据

全文检索,分析

日志管理

2. 环境

本文使用 elasticsearch-7.10.0

不同的jdk版本要使用适配的es版本
最新es与jdk适配图

shell 复制代码
elasticsearch-7.10.0-windows-x86_64\elasticsearch-7.10.0\bin

下载后在bin中点击 elasticsearch.bat 启动es

默认端口是9200

es有几个重要概念

  • 索引:index 类似数据库中的表,一个索引可以理解为一个表
  • 文档:doc 类似数据库中的行,一个文档可以理解为一行数据
  • 倒排索引:数据库中的id一般是 :
    id(1001) - > name("zhang san"), type("man"),es进行分词 建立一个"zhang " -> 1001和 "san" -> 1001就是倒排索引

3. postman操作索引

3.1 创建索引

注:以下操作 以索引名为product为例

注:域名前表示请求类型

rust 复制代码
// 请求类型
post
// 域名
http://localhost:9200/product

3.2 查看索引

rust 复制代码
// 请求类型
get
// 域名
http://localhost:9200/product

3.3 查看所有索引

rust 复制代码
// 请求类型
get
// 域名
http://localhost:9200/_cat/indices?v

3.4 删除索引

rust 复制代码
// 请求类型
delete
// 域名
http://localhost:9200/product

4. postman操作文档

4.1 添加文档

注:以下操作 以索引名为product为例

注:域名前表示请求类型

注:以下使用1001作为文档唯一id,可以不填,es会创建一个唯一id

注:_doc为固定写法表示操作文档

rust 复制代码
// 请求类型
post
// 域名
http://localhost:9200/product/_doc/1001
rust 复制代码
// 请求体body
{
    "title":"小米手机",
    "category":"小米",
    "image":"http://www.sean.com/xm.jpg",
    "price":10000
}

4.2 查询文档

rust 复制代码
// 请求类型
get
// 域名
http://localhost:9200/product/_doc/1001

4.3 查询全部文档

rust 复制代码
// 请求类型
get
// 域名
http://localhost:9200/product/_search

4.4 更新文档

rust 复制代码
// 请求类型
put
// 域名
http://localhost:9200/product/_doc/1001
rust 复制代码
// 请求体body
{
    "title":"华为手机",
    "category":"小米",
    "image":"http://www.sean.com/xm.jpg",
    "price":10000
}

4.5 局部更新文档

rust 复制代码
// 请求类型
post
// 域名
http://localhost:9200/product/_update/1001
rust 复制代码
// 请求体body
{
    "doc": {
        "title":"mi手机"
    }
}

4.6 删除文档

rust 复制代码
// 请求类型
delete
// 域名
http://localhost:9200/product/_doc/1001

4.7 条件查询文档1

rust 复制代码
// 请求类型
get
// 域名
http://localhost:9200/product/_search?q=category:小米

4.8 条件查询文档2

rust 复制代码
// 请求类型
get
// 域名
http://localhost:9200/shopping/_search
rust 复制代码
// 请求体body
{
    "query" : {
        "match" : {
            "category" : "小米"
        }
    }
}

4.9 条件查询文档 limit

分页查询

rust 复制代码
// 请求类型
get
// 域名
http://localhost:9200/shopping/_search
rust 复制代码
// 请求体body
{
    "query" : {
        "match" : {
            "category" : "小米"
        }
    },
    "from": 0,
    "size": 1
}

4.10 条件查询文档 less

只显示一个title字段

rust 复制代码
// 请求类型
get
// 域名
http://localhost:9200/shopping/_search
rust 复制代码
// 请求体body
{
    "query" : {
        "match" : {
            "category" : "小米"
        }
    },
    "from": 0,
    "size": 1,
    "_source":["title"]
}
相关推荐
猎人everest1 小时前
SpringBoot应用开发入门
java·spring boot·后端
Elastic 中国社区官方博客6 小时前
Elasticsearch Open Inference API 增加了对 Jina AI 嵌入和 Rerank 模型的支持
大数据·人工智能·elasticsearch·搜索引擎·ai·全文检索·jina
隔壁老王1566 小时前
mysql实时同步到es
数据库·mysql·elasticsearch
White graces6 小时前
正则表达式效验邮箱格式, 手机号格式, 密码长度
前端·spring boot·spring·正则表达式·java-ee·maven·intellij-idea
web135085886357 小时前
全面指南:使用JMeter进行性能压测与性能优化(中间件压测、数据库压测、分布式集群压测、调优)
jmeter·中间件·性能优化
SunnyRivers8 小时前
关于ES中text类型时间字段范围查询的结构化解决方案
elasticsearch·时间·text·范围查询
API_technology9 小时前
电商搜索API的Elasticsearch优化策略
大数据·elasticsearch·搜索引擎
奋斗的袍子0079 小时前
Spring AI + Ollama 实现调用DeepSeek-R1模型API
人工智能·spring boot·深度学习·spring·springai·deepseek
wolf犭良9 小时前
19、《Springboot+MongoDB整合:玩转文档型数据库》
数据库·spring boot·mongodb
小万编程10 小时前
基于SpringBoot+Vue奖学金评比系统(高质量源码,可定制,提供文档,免费部署到本地)
java·spring boot·后端·毕业设计·计算机毕业设计·项目源码