目录
前言:
Rest Api
查看全部索引:
请求URL:
响应内容:
创建索引:
请求URL:
body内容:
查看索引:
请求URL:
响应内容:
查询索引全部数据:
请求URL:
响应内容:
新增索引数据:
请求URL:
body内容:
响应内容:
修改索引数据:
请求URL:
body内容:
响应内容:
普通匹配查询:
请求URL:
body内容:
响应内容:
新增索引字段:
请求URL:
body内容:
响应内容:
删除索引:
请求URL:
删除索引具体数据:
请求URL:
body内容:
按照日期删除数据:
body内容:
Elasticsearch是一个非常强大的搜索引擎,它可以帮我们对数据进行存储,并快速地搜索及分析数据,如果对Elasticsearch感兴趣的话,可以看一下ElasticSearch7.9.0安装和开启登录密码_Java王小怪的博客-CSDN博客
Elasticsearch在某种程度上我们都是作为数据库使用,那么它肯定是和数据库有着相似之处的。Elasticsearch最关键的就是索引、类型和映射了,其中:
索引_index:(相当于数据库名称);类型 _type:(相当于库中的表,默认为_doc);映射_mapping:(相当于数据库中表的字段)。
GET http://localhost:9200/_cat/indices?v
如果开启了登陆密码,记得在postman中配置Authorization
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open .security-7 iB-5JsanSAG4hVvMkg9EIw 1 0 7 0 25.4kb 25.4kb
green open books WrAL0CMrQuimG7dnMqy0Rg 1 0 5 1 22.6kb 22.6kb
解释返回的数据体内容:
health
: 集群的健康状态,可以是green
(健康)、yellow
(可能存在问题)或red
(严重问题)。status
: 索引的状态,可以是open
(开放搜索)、close
(关闭搜索)或hidden
(不可用于搜索,可能是因为设置了index.hidden
属性)。index
: 索引的名称。uuid
: 索引的唯一标识符。pri
: 主分片的数量。rep
: 副本分片的数量。docs.count
: 索引中文档的数量。docs.deleted
: 自上次刷新以来已删除的文档数量。store.size
: 索引存储的大小(以字节为单位)。pri.store.size
: 主分片存储的大小(以字节为单位)。
PUT http://localhost:9200/books
{
"settings":{
"number_of_shards":3,
"number_of_replicas":2
},
"mappings":{
"log_doc":{
"properties":{
"id": {
"type": "keyword"
},
"language": {
"type": "keyword"
},
"price": {
"type": "keyword"
},
"remark": {
"type": "keyword"
},
"title": {
"type": "keyword"
},
"description": {
"type": "keyword"
}
}
}
}
}
GET http://localhost:9200/books
{
"books": {
"aliases": {},
"mappings": {
"properties": {
"author": {
"type": "keyword"
},
"description": {
"type": "text"
},
"id": {
"type": "keyword"
},
"language": {
"type": "keyword"
},
"price": {
"type": "float"
},
"remark": {
"type": "keyword"
},
"title": {
"type": "text"
}
}
},
"settings": {
"index": {
"refresh_interval": "1s",
"number_of_shards": "1",
"provided_name": "books",
"creation_date": "1691123775089",
"store": {
"type": "fs"
},
"number_of_replicas": "0",
"uuid": "WrAL0CMrQuimG7dnMqy0Rg",
"version": {
"created": "7090099"
}
}
}
}
}
GET http://localhost:9200/books/_search
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "books",
"_type": "esbook",
"_id": "1",
"_score": 1.0,
"_source": {
"id": "1",
"title": "Java 程序设计",
"language": "汉语",
"author": "盖伦",
"price": 18.88,
"description": "哈哈嗨"
}
},
{
"_index": "books",
"_type": "esbook",
"_id": "2",
"_score": 1.0,
"_source": {
"id": "2",
"title": "Python程序设计",
"language": "英语",
"author": "赵信",
"price": 66.88,
"description": "陷阵之至有死无生"
}
},
{
"_index": "books",
"_type": "esbook",
"_id": "3",
"_score": 1.0,
"_source": {
"id": "3",
"title": "PHP 程序设计",
"language": "test",
"author": "宝石",
"price": 88.88,
"description": "我曾踏足山巅,也曾跌入低谷"
}
},
{
"_index": "books",
"_type": "esbook",
"_id": "TWoQy4oBtacv4iJ4HMye",
"_score": 1.0,
"_source": {
"id": "6",
"title": "新增title",
"language": "language",
"author": "xg",
"price": 2799,
"description": "K60Utrl"
}
}
]
}
}
请求方式:POST
http://localhost:9200/sdwan_device/_search
Body内容:
{
"query": {
"match_all": {}
}
}
POST http://localhost:9200/books/_doc
{
"id": "7",
"title": "新增title",
"language": "新增language",
"author": "xg",
"price": 2999,
"description": "Redmi K60Ultra"
}
{
"_index": "books",
"_type": "_doc",
"_id": "UWony4oBtacv4iJ46czs",
"_version": 1,
"result": "created",
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"_seq_no": 6,
"_primary_term": 3
}
POST http://localhost:9200/books/_doc/UWony4oBtacv4iJ46czs/_update
{
"doc": {
"author": "卢十瓦"
}
}
{
"_index": "books",
"_type": "_doc",
"_id": "UWony4oBtacv4iJ46czs",
"_version": 2,
"result": "updated",
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"_seq_no": 7,
"_primary_term": 3
}
POST http://localhost:9200/books/_search
{
"query": {
"term": {
"id": 7
}
}
}
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.1631508,
"hits": [
{
"_index": "books",
"_type": "esbook",
"_id": "UWony4oBtacv4iJ46czs",
"_score": 1.1631508,
"_source": {
"id": "7",
"title": "新增title",
"language": "新增language",
"author": "卢十瓦",
"price": 2999,
"description": "Redmi K60Ultra"
}
}
]
}
}
PUT http://localhost:9200/books/_mapping
{
"properties": {
"createTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.540445,
"hits": [
{
"_index": "books",
"_type": "esbook",
"_id": "UWony4oBtacv4iJ46czs",
"_score": 1.540445,
"_source": {
"id": "7",
"title": "新增title",
"language": "新增language",
"author": "卢十瓦",
"price": 2999,
"description": "Redmi K60Ultra",
"createTime": "2023-09-25 15:18:53"
}
}
]
}
}
DELETE http://localhost:9200/books
POST http://localhost:9200/books/_doc/_delete_by_query
{
"query": {
"match": {
"id": "1"
}
}
}
{
"query": {
"bool": {
"filter": [
{
"range": {
"createTime": {
"from": "2023-08-01 00:00:00",
"to": "2023-08-31 23:59:59"
}
}
}
]
}
}
}
2023/11/15新增:
{"index":{"_index":"books","_type":"_doc"}}
{"id":"d980674","title":"三国演义","language":"汉语","author":"罗贯中","price":158,"description":"四大名著","create Time":"2023-11-15 09:00"}
{"index":{"_index":"books","_type":"_doc"}}
{"id":"d9sad462","title":"海底两万里","language":"English","author":"儒勒·凡尔纳","price":19,"description":"是一本小说","create Time":"2023-11-15 09:00"}
http://localhost:9200/_bulk
Body中选择binary格式,选中文件发送请求即可。