elasticsearch mac下安装使用 java环境的安装

官网   https://www.elastic.co/html

安装java环境java

JAVA如今有8u201与8u202两个版本,这两个版本有什么区别呢?node

这是官方对于奇数版本与偶数版本区别的解释:git

从JDK版本7u71之后,JAVA将会在同一时间发布两个版本的JDK,其中:github

奇数版本为BUG修正并所有经过检验的版本,官方强烈推荐使用这个版本。偶数版本包含了奇数版本全部的内容,以及未被验证的BUG修复,Oracle官方表示:除非你深受BUG困扰,不然不推荐您使用这个版本。macos

安装包下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下载对应的macos版本,按步骤安装便可。
检查是否安装成功,命令行输入:npm

java -version
若输出对应的java版本号等信息即为安装成功。json

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.8.0/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请求没有返回结果。

最后上个效果图吧

相关文章
相关标签/搜索