(十)Modifying Your Data

本文介绍Elasticsearch的数据操作和搜索能力,包括近实时的特性,与SQL平台的区别,以及索引文档的具体方法,如ID的使用和生成。

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

We’ve previously seen how we can index a single document. Let’s recall that command again:

我们之前已经看到了如何索引单个文档。让我们再次回想一下这个命令:
curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "John Doe"
}
'

Again, the above will index the specified document into the customer index, 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:

同样,上面将指定的文档索引到客户索引中,ID为1.如果我们再使用不同(或相同)的文档执行上述命令,Elasticsearch将替换(即重新索引)新文档。 ID为1的现有ID:
curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "Jane Doe"
}
'
The above changes the name of the document with the ID of 1 from "John Doe" to "Jane Doe". If, on the other hand, we use a different ID, a new document will be indexed and the existing document(s) already in the index remains untouched.
以上内容将ID为1的文档名称从“John Doe”更改为“Jane Doe”。另一方面,如果我们使用不同的ID,则会对新文档编制索引,并且索引中已有的现有文档保持不变。
curl -X PUT "localhost:9200/customer/_doc/2?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "Jane Doe"
}
'

The above indexes a new document with an ID of 2.

以上索引ID为2的新文档。
 
 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.
索引时,ID部分是可选的。如果未指定,Elasticsearch将生成随机ID,然后使用它来索引文档。 Elasticsearch生成的实际ID(或前面示例中显式指定的内容)将作为索引API调用的一部分返回。
 
This example shows how to index a document without an explicit ID:
curl -X POST "localhost:9200/customer/_doc?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "Jane Doe"
}
'

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。

转载于:https://www.cnblogs.com/shuaiandjun/p/10272081.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值