欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

用Postman在ElasticSearch上简单的增删改查

程序员文章站 2022-06-17 17:22:13
...

Postman下载地址
打开Postman
用Postman在ElasticSearch上简单的增删改查

添加索引

PUT http://192.168.203.132:9200/school

{
	"settings":{
		"number_of_shards":3,
		"number_of_replicas":1
	},
	"mappings":{
		"student":{
			"properties":{
				"stuName":{"type":"keyword"},
				"age":{"type":"integer"},
				"resume":{"type":"text","analyzer":"ik_smart"},
				"tuition":{"type":"scaled_float","scaling_factor":100},
				"hobbies":{"type":"keyword"},
				"address":{
					"properties":{
						"province":{"type":"keyword"},
						"city":{"type":"keyword"},
						"district":{"type":"keyword"}
					}
				}
			}
		}
	}
}

创建索引前
用Postman在ElasticSearch上简单的增删改查

用Postman在ElasticSearch上简单的增删改查
点击send就是发送创建索引的请求,下面会显示

{
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "school"
}

这就是创建成功的意思,这样就会多出一个叫school的索引
用Postman在ElasticSearch上简单的增删改查

新增数据

POST http://192.168.203.132:9200/school/student/1 再按send发送请求
为索引加一个student的类型,在该类下加一个条d是1的数据

{
	"stuName":"张三",
	"age":18,
	"resume":"我是一个喜欢冒险的人,从小到大,阅人无数",
	"tutition":26800.00,
	"hobbies":["太极","游泳"],
	"address":{
		"province":"江苏",
		"city":"南京",
		"district":"雨花"
	}
}

用Postman在ElasticSearch上简单的增删改查
可以查询到添加的数据
用Postman在ElasticSearch上简单的增删改查

删除数据

DELETE http://192.168.203.132:9200/school/student/1

修改数据

POST http://192.168.203.132:9200/school/student/1/_update

{
	"doc":{
		"tutition":16666.00
	}
}

具体操作,和上面增加类似,不过把请求方式换成post
用Postman在ElasticSearch上简单的增删改查
参看结果发现修改成功
用Postman在ElasticSearch上简单的增删改查

查询

根据ID查询

GET http://192.168.203.132:9200/school/student/1
用Postman在ElasticSearch上简单的增删改查

相关标签: elasticsearch