ElasticSearch安装 (一)

简介

Elasticsearch是一个基于Apache Lucene™的开源搜索引擎。无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进、性能最好的、功能最全的搜索引擎库。

Elasticsearch也使用Java开发并使用Lucene作为其核心来实现所有索引和搜索的功能,但是它的目的是通过简单的RESTful API来隐藏Lucene的复杂性,从而让全文搜索变得简单。

Elasticsearch不仅仅是Lucene和全文搜索,我们还能这样去描述它:

  • 分布式的实时文件存储,每个字段都被索引并可被搜索
  • 分布式的实时分析搜索引擎
  • 可以扩展到上百台服务器,处理PB级结构化或非结构化数据

安装es5.5.0

elasticsearch主要还是基于linux命令的一个服务器,虽然在window下也可以本地用,但是会出现一下乱七八糟的问题。我是基于阿里云CentOS 7.2 64位的,jdk1.8。
下载elasticsearch-5.5.0.zip

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.zip
unzip elasticsearch-5.5.0.zip

安装注意事项

  1. 服务器的内存不足 ( 错误处理) 设置内存小一点儿
 	 cd elasticsearch-5.5.0/config
  	 vi jvm.options 
	-Xms2g      变成这样-------------->     -Xms512m
	-Xmx2g      变成这样-------------->     -Xms512m
  1. 新建用户和组 【ES不能在root用户下启动】
	groupadd elasticsearch  
    useradd testes -g elasticsearch  
    chown -R testes:elasticsearch elasticsearch-5.5.0/ 
  1. 修改配置
	vi /etc/security/limits.conf
	在最后添加下面内容,已经有了的话就覆盖
	* soft nofile 65536
	* hard nofile 131072
	* soft nproc 2048
	* hard nproc 4096
	
	vi /etc/security/limits.d/90-nproc.conf 
	#修改为
	* soft nproc 2048
	
	vi /etc/sysctl.conf 
	vm.max_map_count=655360
	#运行 查看
	sysctl -p

	进入elasticsearch.yml目录下 找到这个注释,然后改成
	bootstrap.memory_lock: false
	bootstrap.system_call_filter: false
	#network.host: 192.168.0.1
	改成 
	network.host: 0.0.0.0
  1. 运行ES
	-d表示在后台启动服务
	./elasticsearch -d
	curl localhost:9200

	查看服务是否正常启动
	ps -ef | grep ela 

运行es

添加一个索引信息,索引为movies,类型为movie,ID为1
title,director,year,genres为索引的内容

PUT /movies/movie/1
{
    "title": "The Godfather",
    "director": "Francis Ford Coppola",
    "year": 1972,
    "genres": ["Crime", "Drama"]
} 

会在右边看到这个东西说明索引创建成功,索引为movies,类型为movie,id为1.版本号为1,因为是首次创建,所以result为created

查找索引信息
GET /_search #搜索全部
http://192.168.100.58:9200/posts/doc/_search
刚刚添加的索引信息被搜索出来了。

es 第三方 api

https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-bulk.html

猜你喜欢

转载自blog.csdn.net/yangsen159/article/details/85631428