安装java环境
JAVA现在有8u201与8u202两个版本,这两个版本有什么区别呢?
这是官方对于奇数版本与偶数版本区别的解释:
从JDK版本7u71以后,JAVA将会在同一时间发布两个版本的JDK,其中:
奇数版本为BUG修正并全部通过检验的版本,官方强烈推荐使用这个版本。偶数版本包含了奇数版本所有的内容,以及未被验证的BUG修复,Oracle官方表示:除非你深受BUG困扰,否则不推荐您使用这个版本。
安装包下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下载对应的macos版本,按步骤安装即可。
检查是否安装成功,命令行输入:
java -version
若输出对应的java版本号等信息即为安装成功。
2. brew 安装elasticsearch
命令行输入:
brew update
brew install elasticsearch
安装过程遇到问题:
==> Downloading https://artifacts.elastic.co/downloads/elasticsearch/elasticsear
######################################################################## 100.0%
Error: parent directory is world writable but not sticky
Please report this bug:
https://docs.brew.sh/Troubleshooting
解决方法:
cd /private/
sudo chmod +t /tmp
重新执行命令:
brew install elasticsearch
即可安装成功。
3. 检验
命令行输入:
cd /usr/local/Cellar/elasticsearch/6.6.1/bin
elasticsearch
bin/elasticsearch -d 后台启动
启动服务
在浏览器输入:
http://127.0.0.1:9200/
浏览器返回如下json文件:
{ "name" : "4PeKOCX", "cluster_name" : "elasticsearch_11111", "cluster_uuid" : "RCa4OvqzQ1KRVLiF8NJg0A", "version" : { "number" : "6.6.1", "build_flavor" : "oss", "build_type" : "tar", "build_hash" : "1fd8f69", "build_date" : "2019-02-13T17:10:04.160291Z", "build_snapshot" : false, "lucene_version" : "7.6.0", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" }
问题
"status": 406 Content-Type header [text/plain] is not supported
创建索引报错
请求方式: put
{
"title": "My first blog entry",
"text": "Just trying this out...",
"date": "2014/01/01"
}
返回值
{
"error": "Content-Type header [text/plain] is not supported",
"status": 406
}
解决方法:
header 设置错了,应该是 application/json
如果是用 postman 的话,可以进入Body,然后选择 raw JSON(application/json)格式
问题:
{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "drama"
}
},
"filter": {
"term": { "year": 1962 }
}
}
}
}
解决方法:
过滤查询已被弃用,并在ES 5.0中删除。现在应该使用bool / must / filter查询
{
"query": {
"bool": {
"must": {
"query_string": {
"query": "drama"
}
},
"filter": {
"term": { "year": 1962 }
}
}
}
}
下载安装中文分词插件。这里使用的是 ik,也可以考虑其他插件(比如 smartcn)
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.0/elasticsearch-analysis-ik-6.3.0.zip
安装elasticsearch-head 插件
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start
首先访问node.js官网(https://nodejs.org/en/download/)
点击下载完后,一路点安装 就安装完成了
然后打开-终端-输入node -v 会返回当前安装的版本号 npm -v
由于head插件监听的端口是9100,而elasticsearch的REST接口的端口是9200,
因此需要设置elasticsearch允许跨域访问,才能使用head插件,
编辑elasticsearch安装目录下的config目录下的elasticsearch.yml文件,添加如下2行配置:
http.cors.enabled: true http.cors.allow-origin: "*"
问题:elasticsearch-head 连不上es
解决方法:
然后重新启动elasticsearch就可以了。重启elasticsearch-head
这个时候我发现原来的options请求,已经变成get请求了
分析原因:
可能是因为elasticsearch-head发送请求的时候,跨域了,所以变成options,让options去发现有什么可以请求的方法,而options请求没有返回结果。
最后上个效果图吧