(十)Modifying Your Data

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.git

Elasticsearch幾乎實時提供數據操做和搜索功能。默認狀況下,從索引/更新/刪除數據到搜索結果中顯示的時間,您可能會有一秒鐘的延遲(刷新間隔)。這是與SQL等其餘平臺的重要區別,其中數據在事務完成後當即可用。
 

Indexing/Replacing Documents

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

咱們以前已經看到了如何索引單個文檔。讓咱們再次回想一下這個命令:
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:json

一樣,上面將指定的文檔索引到客戶索引中,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.app

以上索引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.dom

請注意,在上述狀況下,咱們使用POST動詞而不是PUT,由於咱們沒有指定ID。
相關文章
相關標籤/搜索