es 学习笔记
1.安装ES略过自行百度
2.操作ES 通过postman 愉快的玩耍
3.明确几个概念: 索引类似数据库 type 类似数据库中表 文档对应数据库中每条记录
4.操作:
创建一个索引:student_es
发送put 请求:(http://xx.xx.xx.89:9200/student_es) json 传递:
{
“mappings”: {
“stu”: {
“properties”: {
“id”: {
“fields”: {
“keyword”: {
“ignore_above”: 256,
“type”: “keyword”
}
},
“type”: “long”
},
“stu_age”: {
“fields”: {
“keyword”: {
“ignore_above”: 256,
“type”: “keyword”
}
},
“type”: “integer”
},
“stu_name”: {
“fields”: {
“keyword”: {
“ignore_above”: 256,
“type”: “keyword”
}
},
“type”: “text”
}
}
}
}
}
返回结果:
{
“acknowledged”: true,
“shards_acknowledged”: true
}
添加记录 post
(http://xx.x.xx.xx:9200/student_es/stu/1)
{
“id”:“9527”,
“stu_age”:20,
“stu_name”:“fdy”
}
返回结果:
{
“_index”: “student_es”,
“_type”: “stu”,
“_id”: “1”,
“_version”: 1,
“result”: “created”,
“_shards”: {
“total”: 2,
“successful”: 1,
“failed”: 0
},
“created”: true
}
根据ID查询 post
(http://xx.xx.xx.xx:9200/student_es/stu/_search?pretty)
{
“query”:{
“match”:{
“id”:“9527”
}
}
}
返回结果:
{
“took”: 93,
“timed_out”: false,
“_shards”: {
“total”: 5,
“successful”: 5,
“failed”: 0
},
“hits”: {
“total”: 1,
“max_score”: 1,
“hits”: [
{
“_index”: “student_es”,
“_type”: “stu”,
“_id”: “1”,
“_score”: 1,
“_source”: {
“id”: “9527”,
“stu_age”: 20,
“stu_name”: “fdy”
}
}
]
}
}
springboot 集成:
采用万能版本兼容方法RestClient
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>6.4.0</version>
</dependency>
<!--引入json进行HTTP序列化-->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>