1、安装elasticsearch,教程:https://www.imooc.com/article/20367
2、安装elasticsearch-head插件,教程:https://github.com/mobz/elasticsearch-head
3、也可以不用安装这个插件,谷歌浏览器自带其扩展程序:直接搜索:elasticsearch-head安装即可
4、双击elasticsearch.bat,启动elasticsearch
5、创建索引:打开postman 工具,选择put请求,url输入:http://localhost:9200/customer?pretty
执行第一行返回以下内容,这里我们使用PUT谓词创建了一个名叫 customer 的索引,在后面跟上 pretty 表示如果有数据返回的话,用格式化后的JSON返回数据
{
"acknowledged": true,
"shards_acknowledged": true
}
6、创建类型:http://localhost:9200/customer/external/1?pretty
参数:
{ "name": "John Doe" }
返回内容如下:
{ "_index": "customer", "_type": "external", "_id": "1", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "created": true }
从以上可以看出,一个新的客户文档成功被索引到 customer索引的 extenal 类型中,并且我们在索引的时候指定文档的内部id值为1。
值得注意的是, Elasticsearch 不需要在你索引文档到某个索引之前,明确的创建一个索引。比如上一个例子,如果 customer索引不存在, Elasticsearch将自动创建该索引。
再来看下我们刚刚索引的文档
扫描二维码关注公众号,回复:
2604295 查看本文章
GET /customer/external/1?pretty
返回内容如下:
{ "_index": "customer", "_type": "external", "_id": "1", "_version": 1, "found": true, "_source": { "name": "John Doe" } }