Elasticsearch 入門(一)

零、 Basic Concept

Elasticsearch 是基于Lucene 的搜索引擎。Lucene 是一個強大的開源搜索庫。它倆關系就像是汽車 跟引擎的關系。Elasticsearch 是一個實時的分布式搜索分析引擎,被用作全文檢索、結構化搜索、分析以及這三個功能的組合。官方定義:

Elasticsearch is a distributed, RESTful search and analytics engine capable of solving a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data so you can discover the expected and uncover the unexpected.

一、Install Elasticsearch on MacOS

  • 安裝java ,oracle官網安裝,確認安裝成功。
  $ java --version  
  • brew 安裝Elasticsearch
$ brew update
$ brew install elasticsearch 
$ brew info elasticsearch

二、Try it out

$ elasticsearch
chrome plugin: json viewer

一個 Elasticsearch 請求和任何 HTTP 請求一樣由若干相同的部件組成:

$curl -X<VERB> '<PROTOCOL>://<HOST>:<PORT>/<PATH>?<QUERY_STRING>' -d '<BODY>'

Elasticsearch HTTP 服務的端口號,默認是 9200.
PATH是API 的終端路徑(例如 _count 將返回集群中文檔數量)。
QUERY_STRING 是任意可選的查詢字符串參數
BODY是一個 JSON 格式的請求體 (如果請求需要的話)

三、CRUD

新增記錄

$curl -X POST 'localhost:9200/accounts/post' -d'{ "title":"elasticsearch","content":"hello, elasticsearch2","tag":"elasticsarch2"}'

修改記錄

$curl -X PUT 'localhost:9200/accounts/post/1' -d'{ "title":"elasticsearch","content":"update, elasticsearch","tag":"updated"}'

刪除記錄

$curl -X DELETE '127.0.0.1:9200/accounts/post/1'

四、參考鏈接

[ElasticSearch 官方網站](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started.html

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容