ElasticSearch修改数据

Paste_Image.png

Elasticsearch provides data manipulation and search capabilities in near real time. By default, you can expect a one second delay (refresh interval) from the time you index/update/delete your data until the time that it appears in your search results. This is an important distinction from other platforms like SQL wherein data is immediately available after a transaction is completed.

  • ElasticSearch不像SQL类型数据库一样事物结束后即返回数据,而是有个刷新间隔

Indexing/Replacing Documents

PUT /customer/external/1?pretty
{
"name": "John Doe"
}

PUT /customer/external/1?pretty
{
"name": "Jane Doe"
}

执行上面的命令,第一条在新增一条记录,第二条因为id相应则会更新记录的name值

Again, the above will index the specified document into the customer index, external type, with the ID of 1. If we then executed the above command again with a different (or same) document, Elasticsearch will replace (i.e. reindex) a new document on top of the existing one with the ID of 1:

When indexing, the ID part is optional. If not specified, Elasticsearch will generate a random ID and then use it to index the document. The actual ID Elasticsearch generates (or whatever we specified explicitly in the previous examples) is returned as part of the index API call.

This example shows how to index a document without an explicit ID:

POST /customer/external?pretty
{
"name": "Jane Doe"
}

注意id是可选的,如果不指定id,则es会生成默认的

Paste_Image.png

Note that in the above case, we are using the POST verb instead of PUT since we didn’t specify an ID.

注意上面使用了post而不是put方式,因为我们没有制定ID,这句话是什么意思呢,简单的理解可能不完全对,PUT是更新操作,POST是新增操作,对于post还是put方式可以参考下面的连接
HTTP协议中PUT和POST使用区别

Deleting Documents

Deleting a document is fairly straightforward. This example shows how to delete our previous customer with the ID of 2:
DELETE /customer/external/2?pretty

上面是删除id=2的记录

See the Delete By Query API to delete all documents matching a specific query. It is worth noting that it is much more efficient to delete a whole index instead of deleting all documents with the Delete By Query API.

  • 删除满足查询条件的记录请查看 Delete By Query API 文档

Delete By Query API

下面详细介绍,这部分在这里没有详细看,后续用到再看吧

https://www.elastic.co/guide/en/elasticsearch/reference/5.3/docs-delete-by-query.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,969评论 19 139
  • elasticsearch使用--简单入门(一) 一、下载安装 安装java 下载elasticsearch相应版...
    ifeelok0319阅读 332评论 0 0
  • 基础概念 Elasticsearch有几个核心概念,从一开始理解这些概念会对整个学习过程有莫大的帮助。 接近实时(...
    山天大畜阅读 2,122评论 0 4
  • 文/依风 望不尽 千古风沙 岁月洗不尽 人间铅华 往事几许 处处是您的牵挂 暮至花甲 心却还放不下 您说 养育只是...
    新雅遇见读书阅读 629评论 0 0
  • 很多人都喜欢把自己和伴侣非常恩爱的一面展示给朋友。其实,那些在朋友圈秀恩爱的人,未必得到了真正的疼爱。 很多恋爱中...
    北府涵阅读 342评论 29 11