SpringCloud

linux下安装ElasticSearch以及简单使用

2019-06-12  本文已影响0人  乔治m2

6.0.0版本以上要jdk1.9才能启动,如果不是jdk1.9则会报错:

OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.

Ubuntu中启动ElasticSearch报错:max virtual memory areas vm.max_map_count [65530] is too low, increase to a

linux下启动elasticsearch报错BindTransportException[Failed to bind to [9300-9400]解决办法

打开配置文件elasticsearch.yml 将 network.host: 192.168.0.1 修改为本机IP 0.0.0.0

es下载地址sudo wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.15.zip

启动命令: sh ./bin/elasticsearch

1.docker 错误排查:无法进入容器.

#docker exec -it 3c1d bash
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "process_linux.go:110: decoding init error from pipe caused \"read parent: connection reset by peer\""   
**解决**

降低docker容器的版本
yum downgrade docker docker-client docker-common

2.进入后无法使用vim

# apt-get update 升级vim
# apt-get install vim 安装vim

elasticsearch-head的使用

下载地址https://github.com/mobz/elasticsearch-head/archive/master.zip

wget https://github.com/mobz/elasticsearch-head/archive/master.zip  #下载
unzip xxx   #解压
#进入文件
npm install   #安装npm
npm run start #启动它  默认使用9100端口

设置集群

集群通过节点来绑定到一起cluster.name

主节点配置master

http.cors.enabled: true
http.cors.allow-origin: "*"
cluster.name: wuli
node.name: master
node.master: true
network.host: 0.0.0.0
discovery.zen.ping.unicast.hosts: ["192.168.0.101:8300"] # 如过是一台机子,要带端口

奴隶节点的配置

cluster.name: wali  # 集群的名字
node.name: slave1   # 当前节点的名字
network.host: 0.0.0.0   #当前节点的ip地址
http.port:   # 如果是docker可以不用设置
discovery.zen.ping.unicast.hosts: ["192.168.0.101:9300"]  # 如过是一台机子,要带端口

利用postman创建索引

用put方法添加索引

192.168.0.101:9200/people 方法: put

{
    "settings": {
        "number_of_shards": 3,  //设置分片数
        "number_of_replicas": 1  //设置备份数
    },
    "mappings": {
        "man": {
            "properties": {
                "name": {
                    "type": "text"
                },
                "country": {
                    "type": "keyword"
                },
                "age": {
                    "type": "integer"
                },
                "date": {
                    "type": "date",
                    "format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd||epoch_millis"
                }
            }
        }
    }
}

用put方法添加数据

192.168.0.101:9200/people/man/3

{
    "name": "mike",
    "country": "usa",
    "age": 18,
    "date": "1999-10-2"
}

用delete方法删除索引文档

192.168.0.101:9200/people/man/3
删除索引
192.168.0.101:9200/people

查询post,get

192.168.0.101:9200/book/_search

//查询改索引下所有的数据
{
    "query": {
        "match_all": {}   
    }
}
//模糊查询
{
    "query": {
        "match": {
            "title": "compur"
        }
    }
}
//精确查询
{
    "query": {
        "match_phrase": {
            "title": "computer科学"
        }
    }
}
//多个字段的模糊查询
{
    "query": {
        "multi_match": {
            "query": "computer",
            "fields": ["title","auther"]
        }
    }
}
//语法查询
{
    "query": {
        "query_string": {
            "query": "computer OR news",
            "fields": ["title","auther"]  //可以写匹配的字段
        }
    }
}
//字段查询
{
    "query": {
        "term": {
            "word_count": 1002
        }
    }
}
//范围查询
{
    "query": {
        "range": {
            "word_count": {
                "gte": 1000,
                "lte": 100009
            }
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读