Elasticsearch 入門: Hello World

  1. 安裝 Elasticserach:

    1. 下載最新的elasticsearch:官網(wǎng)地址: https://www.elastic.co/downloads/elasticsearch

    2. 解壓縮之后,把 elasticsearch-<version>/bin 路徑放到 bash_profile 里

    3. 運(yùn)行

      elasticsearch
      
    4. 用命令行測(cè)試

      curl 'http://localhost:9200/'
      

      應(yīng)給得到類似下面的響應(yīng):

      {
        "name" : "VJ6rpak",
        "cluster_name" : "elasticsearch",
        "cluster_uuid" : "enuYtqaGTaqoSYwErlyZBw",
        "version" : {
          "number" : "6.2.4",
          "build_hash" : "ccec39f",
          "build_date" : "2018-04-12T20:37:28.497551Z",
          "build_snapshot" : false,
          "lucene_version" : "7.2.1",
          "minimum_wire_compatibility_version" : "5.6.0",
          "minimum_index_compatibility_version" : "5.0.0"
        },
        "tagline" : "You Know, for Search"
      }
      
  2. 安裝圖形界面kibana

    1. 下載kibana:官網(wǎng)地址: https://www.elastic.co/downloads/kibana

    2. 解壓縮之后,把 kibana-<version>/bin 路徑放到 bash_profile 里

    3. 中文版教程中還有安裝 sense 的步驟,但 Kibana 從 5.0.1 版本開(kāi)始就已經(jīng)自帶了調(diào)試工具,可以在 kibana 左側(cè)工具欄 DevTools 中找到。

    4. 啟動(dòng)kibana

      kibana
      
    5. 用瀏覽器訪問(wèn)圖形界面:http://localhost:5601

  3. Hello World

    1. 在 DevTools 查詢集群中文檔總數(shù)量

      GET /_count
      {
          "query":{
              "match_all":{}
          }
      }
      
    2. 返回:

      {
        "count": 1,
        "_shards": {
          "total": 5,
          "successful": 5,
          "skipped": 0,
          "failed": 0
        }
      }
      
  4. Python 插件 elasticsearch

    1. 安裝elasticsearch

      pip3 install elasticsearch
      
    2. hello world

      from elasticsearch import Elasticsearch
      import pprint
      es = Elasticsearch()
      doc = {
          "query":{
              "match_all":{}
          }
      }
      res = es.search(body=doc)
      pprint.pprint(res)
      
    3. 應(yīng)該得到下面的結(jié)果:

      {'_shards': {'failed': 0, 'skipped': 0, 'successful': 5, 'total': 5},
       'hits': {'hits': [{'_id': '1',
                          '_index': 'test-index',
                          '_score': 1.0,
                          '_source': {'author': 'kimchy',
                                      'text': 'Elasticsearch: cool. bonsai cool.',
                                      'timestamp': '2018-05-10T10:24:58.396432'},
                          '_type': 'tweet'}],
                'max_score': 1.0,
                'total': 1},
       'timed_out': False,
       'took': 1}
      

我的部分技術(shù)博客將會(huì)同步至騰訊云+社區(qū),邀請(qǐng)大家一同入駐:https://cloud.tencent.com/developer/support-plan?invite_code=3hp099lflrokw

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容