Elasticsearch在windows上安裝與使用


Elasticsearch簡稱ES。

是一個全文搜索服務器,也可作為NoSQL數據庫,存儲任意格式的文檔和數據,也可做大數據的分析,是一個跨界開源產品。

ES的特點:

  全文搜索引擎

  文檔存儲和查詢

  大數據分析

  提供了REST API,用來簡化對ES的操作

  常常配合傳統數據庫一起使用,ES用來負責大數據的查詢、搜索、統計分析

1.下載

elasticsearch-6.8.3.zip  https://www.elastic.co/downloads/past-releases#elasticsearch

2.啟動

解壓 elasticsearch-6.8.3.zip

打開cmd,進入elasticsearch的bin

elasticsearch

9200端口是對外的RESTFul接口,9300端口是ES內部使用的端口

啟動后在瀏覽器 http://localhost:9200/

說明:

  name代表這台ES的名字

  cluster_name默認名字是elasticsearch。ES的集群方式是通過廣播在同一個網絡中尋找cluster_name一樣的ES

  如果想修改配置,可以在config/elasticsearch.yml配置

3.基本概念

  Index:是Document的集合,Index包含了Type,相當於數據庫

  Type:用來進一步組織Document,一個Index可以有多個Type,相當於表

  Document:文檔,是ES能夠存儲和搜索的基本信息,Document屬於Type,相當於行數據,json格式的

  Node:節點,是集群里的一台ES Server,用於Document的存儲和查詢

  Shards:分區,Index超過了單個節點存儲的限制,就會將Index進行分區

  Replicas:復制分區,將Index分為多個分區,Index的分區為主分區,復制的分區為復制分區

4.基本使用

  (1)添加文檔

curl -XPOST 'localhost:9200/store/category/1?pretty' -H 'Content-type:application/json' -d'{"name":"soap","type":"cleaning","postDate":"2019-9-15","message":"this is a first data"}'

  (2)根據主鍵查詢

curl -XGET 'localhost:9200/store/category/1?pretty'

   (3)根據主鍵更新

 curl -XPUT 'localhost:9200/store/category/1?pretty' -H 'Content-type:application/json' -d'{"name":"soap123","type":"cleaning","postDate":"2019-9-15T23:10:10","message":"update data"}'

   只更新message

curl -XPOST 'localhost:9200/store/category/1?pretty' -H 'Content-type:applicat                                                                                                                ion/json' -d'{"doc":{"message":"only update message"}}'

   (4)根據主鍵刪除

curl -XDELETE 'localhost:9200/store/category/1?pretty'

   (5)搜索

curl -XPOST 'localhost:9200/store/category/_search?pretty'

     全文搜索

 curl -XPOST 'localhost:9200/store/category/_search?pretty' -H 'Content-type:application/json' -d'{"query":{"match":{"message":"data"}}}'

    精確搜索

curl -XPOST 'localhost:9200/store/category/_search?pretty' -H 'Content-type:application/json' -d'{"query":{"term":{"type":"cleaning"}}}'

     查詢總數

  將_count替換_search

curl -XPOST 'localhost:9200/store/category/_count?pretty' -H 'Content-type:application/json' -d'{"query":{"match":{"message":"data"}}}'

     聯合查詢

curl -XPOST 'localhost:9200/store/category/_search?pretty' -H 'Content-type:application/json' -d'{"query":{"bool":{"must":[{"term":{"type":"eating"}},{"match":{"message":"second"}}]}}}'

     翻頁,使用from和size

 curl -XPOST 'localhost:9200/store/category/_search?pretty' -H 'Content-type:application/json' -d'{"from":1,"size":1,"query":{"match":{"message":"data"}}}'

 說明:

  安裝了git就會帶有curl功能了

 數據可視化


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM