Elasticsearch 插入数据
在前一章中我们已经安装好了Elasticsearch 基本环境
这一章我们该开始学习关于ElasticSearch最基本的CURD操作了
1、设置索引

或者使用
PUT /produtcs { "settings" : { "number_of_shards" : 3, "number_of_replicas" : 1 } }

2、删除索引
DELETE /produtcs

3、创建文档
在创建文档时_index、_type、_id三者唯一确定一个文档。所以要想保证文档是新加入的,最简单的方式是使用POST方法让Elasticsearch自动生成唯一_id,或者手动指定一个_id
对于_index、_type和抽象的理解为我们常用的关系数据库中的数据(_index)和表(_type)
添加:
http://192.168.3.75:9200/ POST product/info/1 { "title": "My first blog entry4", "description": "I am starting to get the hang of this4", "price": 5, "onSale": false, "createDate": "2017-11-20" }

更新:
POST product/info/1 { "title": "My first blog test", "description": "I am starting to get the hang of this4", "price": 12, "onSale": false, "createDate": "2017-11-20" }

查询:
GET product/info/1

删除:
DELETE product/info/1

后续会推出,复杂查询,以及批量操作,而且其性能也是非常不错,本人测试过单次批量10万的添加操作用时不到30秒,并且大数据(2亿)查询也非常快


浙公网安备 33010602011771号