前言须知
Elaticsearch,简称为es, es是一个开源的高扩展的分布式全文检索引擎,它可以近乎实时的存储、检索数据;本身扩展性很好,可以扩展到上百台服务器,处理PB级别的数据。es也使用Java开发并使用Lucene作为其核心来实现所有索引和搜索的功能,但是它的目的是通过简单的RESTful API来隐藏Lucene的复杂性,从而让全文搜索变得简单
核心概念:
- 索引 index
- 字段 Field
- 映射 mapping
- 文档 document
- 接近实时 NRT
- 集群 cluster
- 节点 node
- 分片和复制 shards&replicas
1.安装及配置(windows)
下载zip压缩文件解压,将解压缩的文件夹放在软件盘下即为安装成功
百度网盘 https://pan.baidu.com/s/1-W9-8jntGYOozkz9pJAY7w
提取码:3r3b
修改elasticsearch配置文件:config/elasticsearch.yml,增加以下两句命令:
http.cors.enabled: true
http.cors.allow-origin: "*"
2.在浏览器上安装head插件便于图形化管理
打开google浏览器,进入google网上应用商店,URL:https://chrome.google.com/webstore/category/extensions
收索ElasticSearch Head,然后点击收索的dead插件自动安装,最后重启浏览器,输入 http://localhost:9200/ 连接到本地的ElasticSearch服务
3.新建index索引库(使用postman工具)
使用PUT方法新增:http://localhost:9200/index_name
4.删除索引库
使用DELETE方法新增:http://localhost:9200/index_name
5.创建索引库映射
-
先创建一个students索引库
-
使用POST方法修改索引库:
请求URL:http://localhost:9200/index_name/_mappings
请求体为:{ "properties":{ "id":{ "type":"long" }, "name":{ "type":"keyword" }, "age":{ "type":"long" }, "team":{ "type":"keyword" }, "country":{ "type":"keyword" }, "desc":{ "type":"text" } } }
6.索引库映射可以新增域但是不可以修改域(我所了解)
这里添加一个性别域(字段)
7.插入数据到students索引库中
插入数据使用PUT方法:http://localhost:9200/students/_doc/[id]
当填写了id值之后会以指定值在索引库创建对应id的文档,不填写会随机生成字符串作为id