Elasticsearch的安裝(windows)

0x00 教程內容

  1. 下載並運行elasticsearch
  2. 下載並配置elasticsearch-head
  3. 構建項目所需的索引

0x01 下載並運行elasticsearch

1. 下載

(下載指定版本的網址:https://www.elastic.co/downloads/past-releases)
在這裏插入圖片描述
a. 點擊網頁頭部的downloads
在這裏插入圖片描述
b. 點擊Elasticsearch的Download:
在這裏插入圖片描述
c. 會顯示最新版本,可以點擊網頁中部的past releases下載之前的版本:
在這裏插入圖片描述
d. 搜索想要的版本,這裏下載Elasticsearch 5.6.1版本,點擊download:
在這裏插入圖片描述
e. 點擊相對於的系統版本,這裏是win,選zip格式,如是linux或mac則選擇tar:
在這裏插入圖片描述

2. 解壓

a. 解壓(如:E:\SmallTools\elasticsearch-5.6.1)
在這裏插入圖片描述

3. 運行

a. 執行bin路徑下的:elasticsearch.bat
b. 等執行完成後在瀏覽器輸入:localhost:9200
c.可看到以下信息:
在這裏插入圖片描述

0x02 下載並配置elasticsearch-head

1. 下載並解壓插件

github搜:elasticsearch head
a. 點擊第一個:
在這裏插入圖片描述
b. 點擊下載鏈接:
在這裏插入圖片描述
c. 解壓(如:E:\SmallTools\elasticsearch-head-master)

2. 安裝node.js

a. node.js安裝(參考教程:https://blog.csdn.net/Sweet__Cat/article/details/77726052)
我本地安裝的版本爲:node.js v6.12.3

C:\Users\Administrator>node -v
v6.12.3

C:\Users\Administrator>
3. 初始化並配置elasticsearch-head插件

a. 按鍵盤win+R,輸入cmd,點擊運行
輸入:
e:
回車,輸入(需改爲自己的解壓路徑):
cd E:\SmallTools\elasticsearch-head-master
在這裏插入圖片描述
b. 然後執行(沒有error表示成功)
npm install
在這裏插入圖片描述
c. 繼續執行:
npm run start
在這裏插入圖片描述
d. 在瀏覽器中打開提示的端口
在這裏插入圖片描述
e. 配置Elasticsearch與elasticsearch-head插件關聯
修改E:\SmallTools\elasticsearch-5.6.1\config\elasticsearch.yml
添加下面兩行:

http.cors.enabled: true
http.cors.allow-origin: "*"

在這裏插入圖片描述
添加(注意冒號後面有空格!!!!):
f. 關掉之前的Elasticsearch並重新啓動,刷新瀏覽器發現狀態已更新爲green:
http://localhost:9100/
在這裏插入圖片描述

0x03 構建項目所需的索引

1. 編寫Elasticsearch索引
{
  "settings": {
    "number_of_replicas": 0
  },
  "mappings": {
    "house": {
      "dynamic": false,
      "properties": {
        "houseId": {
          "type": "long"
        },
        "title": {
          "type": "text",
          "index": "analyzed"
        },
        "price": {
          "type": "integer"
        },
        "area": {
          "type": "integer"
        },
        "createTime": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "lastUpdateTime": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "cityEnName": {
          "type": "keyword"
        },
        "regionEnName": {
          "type": "keyword"
        },
        "direction": {
          "type": "integer"
        },
        "distanceToSubway": {
          "type": "integer"
        },
        "subwayLineName": {
          "type": "keyword"
        },
        "subwayStationName": {
          "type": "keyword"
        },
        "tags": {
          "type": "text"
        },
        "street": {
          "type": "keyword"
        },
        "district": {
          "type": "keyword"
        },
        "description": {
          "type": "text",
          "index": "analyzed"
        },
        "layoutDesc" : {
          "type": "text",
          "index": "analyzed"
        },
        "traffic": {
          "type": "text",
          "index": "analyzed"
        },
        "roundService": {
          "type": "text",
          "index": "analyzed"
        },
        "rentWay": {
          "type": "integer"
        }
      }
    }
  }
}
2. 執行Elasticsearch索引

a. 按序號執行,注意修改路徑(也可以使用postman或者谷歌插件Restlet Client)
在這裏插入圖片描述
b. 出現此信息,表示索引構建成功!
在這裏插入圖片描述

0xFF 總結

  1. 0x01、0x02參考慕課網瓦力老師的課程《ElasticSearch入門》
  2. 0x03參考慕課網瓦力老師的課程《BAT大牛親授基於ElasticSearch的搜房網實戰》
  3. 同學們可以不安裝node.js和elasticsearch-head插件,但爲了方便,還是同步教程比較好,node.js的可以安裝更高版本,建議安裝,因爲後期項目實戰以及前端框架Vue教程會使用到。

作者簡介:邵奈一

大學大數據講師、大學市場洞察者、專欄編輯

公衆號、微博、CSDN邵奈一

本系列課均爲本人:邵奈一原創,如轉載請標明出處

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章