1. 程式人生 > >SpringBoot + Elasticsearch之踩坑記錄

SpringBoot + Elasticsearch之踩坑記錄

spring boot 1.x支援elasticsearch <5.x

elasticsearch安裝:按官網安裝步驟:

(1)curl -L -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.3.4/elasticsearch-2.3.4.tar.gz

(2)tar -xvf elasticsearch-2.3.4.tar.gz

(3)cd elasticsearch-2.3.4/bin

(4)./elasticsearch

elasticsearch配置:

開啟ES的config資料夾下的elasticsearch.yml;

配置檔案如下:

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please see the documentation for further information on configuration options:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
 cluster.name: my-name
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
 node.name: name
#
# Add custom attributes to the node:
#
# node.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
 path.data: /opt/modules/elasticsearch-2.3.4/data
#
# Path to log files:
#
 path.logs: /opt/modules/elasticsearch-2.3.4/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: false
#bootstrap.system_call_filter: false
#
# Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory
# available on the system and that the owner of the process is allowed to use this limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
 network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
 http.port: 9200
 transport.tcp.port: 9300
 transport.tcp.compress: true
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# discovery.zen.ping.unicast.hosts: ["host1", "host2"]
 discovery.zen.ping.unicast.hosts: ["xx.xxx.xxx.xxx"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
#
# ---------------------------------- Various -----------------------------------
#
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true
 http.cors.enabled: true
 http.cors.allow-origin: "*"
# elasticsearch plugin ik 
 index.analysis.analyzer.ik.type: "ik"

elasticsearch - ik分詞器安裝:

首先上git根據自己的ES版本號下載對應版本的ik。例如ES2.3.4的 https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v1.9.4(這裡推薦下載第一個zip,可以省去mvn,當初第一次mvn真的花了很久時間)。

(1)將下載的zip解壓縮,獲得config資料夾、ik的一個jar檔案、一些其他的檔案。

config資料夾改名為analysis-ik,放入ES的config中

剩餘檔案放入ES的plugins目錄下的analysis-ik資料夾中(資料夾沒有,需要自己建立)。

 

重要!!!!!!!linux一些環境配置可參見:https://blog.csdn.net/daerzei/article/details/79761086

spring boot 2.x支援elasticsearch >5.x

es安裝可參考此部落格:https://blog.csdn.net/daerzei/article/details/79761086

分詞器可參考:https://blog.csdn.net/u014315200/article/details/78630001

配置檔案與上面的大相同,將配置檔案最下面的分詞器刪除掉就行了,刪除如下語句

index.analysis.analyzer.ik.type: "ik"

 

head的安裝:

先安裝nodejs,然後再安裝head

nodejs安裝:https://blog.csdn.net/xiatiancc/article/details/78872157

1、下載head外掛原始碼

https://github.com/mobz/elasticsearch-head

由於elasticsearch5.0版本變化較大,目前elasticsearch5.0 暫時不支援直接安裝,但是head作者提供了另一種安裝方法。

可參見官網地址: https://github.com/mobz/elasticsearch-head