1. 程式人生 > >第七章:文件的操作

第七章:文件的操作

一.建立文件

    建立文件的有兩種方式

    PUT建立文件: 需要指定文件的Id

    POST建立文件: 不需要指定文件ID,Elasticsearch 可以幫我們自動生成 ID,自動生成的 ID 是 URL-safe、 基於 Base64 編碼且長度為20個字元的 GUID 字串

PUT /website/blog/123 {   "title": "My first blog entry",   "text":  "Just trying this out...",   "date":  "2014/01/01" } POST /website/blog/ {   "title": "My second blog entry",   "text":  "Still trying this out...",   "date":  "2014/01/01" }

二.獲取文件

獲取詳細文件資訊在請求的後面加上pretty

GET /website/blog/123?pretty

獲取顯示指定欄位的資訊使用_source,後面跟要顯示欄位

GET /website/blog/123?_source=title,text

獲取只顯示文件中的欄位的資訊

GET /website/blog/123/_source

獲取文件下的所有的資訊

GET /website/blog/_search