1、Elasticsearch的堆栈内存设置建议
![image.png](https://upload-images.jianshu.io/upload_images/9967595-3292925868e93be0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2、elasticsearch.yml设置中文分词器:
/usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.4/elasticsearch-analysis-ik-6.5.4.zip
//安装完,在elasticsearch.yml中添加配置
index.analysis.analyzer.default.type: ik
3、关闭elasticsearch
curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown
![image.png](https://upload-images.jianshu.io/upload_images/9967595-597bda51ab5a749b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-a061dc15af281ff0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4、监控客户端状态的插件head;
http://localhost:9200/_plugin/head
![image.png](https://upload-images.jianshu.io/upload_images/9967595-131208ff47feb219.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
5、Marvel 图形化监控客户端
http://lcalhost:9200/_plugin/marvel/
![image.png](https://upload-images.jianshu.io/upload_images/9967595-25df51a52e04978d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
6、Health 查看集群状态
![image.png](https://upload-images.jianshu.io/upload_images/9967595-1eb5aac0ef86fb76.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
7、架构
![image.png](https://upload-images.jianshu.io/upload_images/9967595-6d2fa8ae7f585f40.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
8、http://ip:9200/index/type/id
index: dbname
type: dbtable
GET/POST/PUT/DELETE
?pretty 增强可读性
9、mapping 映像,相当于数据类型
10、搜索参数:_search?q=location:Shanghai
11、实例
创建索引文件test,用PUT方法创建
创建mapping文件,//不是elasticsearch的注释,mapping相当于对象
![image.png](https://upload-images.jianshu.io/upload_images/9967595-55727fa8223cb779.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-bc980c2df4e27a14.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
创建检索表达式
![image.png](https://upload-images.jianshu.io/upload_images/9967595-7487ac7ff86320af.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-6978ac7e171f65db.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-f580887a3130364c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-c1f0933acefca159.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-33acde1ea5017486.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
12、用XPUT方式创建索引
![image.png](https://upload-images.jianshu.io/upload_images/9967595-396f732ecbf51a0e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
用_settings修改索引
![image.png](https://upload-images.jianshu.io/upload_images/9967595-2afd3c96a10ea243.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
索引属性:number_of_replicas 索引的副本数量
blocks.read_only 只读 blocks.read 禁止读取 blocks.write blocks.metadata
调取索引的配置:curl -XGET http://ip:port/weibo/_settings
http://xx/weibo1,weibo2/_settings
_all/_settings 所有索引
mar*/_settings
13、插入数据
![image.png](https://upload-images.jianshu.io/upload_images/9967595-857cc25c2c233cf4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
String,Integer,Long,Float,Double,Boolean,Null,Date
14、_stats 索引状态
![image.png](https://upload-images.jianshu.io/upload_images/9967595-f7e9099392bb797a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-ab0c6cb6e6ca5a6c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
15、配置mapping
PUT /{index}/_mapping/{type}
PUT /index/type/_mapping -d '{
"wb":{
"properties": {
"mymessage":{
"type":"String",
"store": true
}
}
}
}'
获取get /index/_mapping/type
_all/_mapping
获取索引某个字段 get /index/_mapping/type/field/user
删除DELETE
16、打开关闭索引文件
curl -XPOST /myindex/_open
curl -XPOST /myindex/_close
检索 curl -XHEAD /myindex -v
XDELETE
清空索引缓存 curl -XPOST /myindex/_cache/clear
刷新索引数据 curl -XPOST /myindex/_refresh
优化索引数据 curl -XPOST /myindex/_optimize
flush /myindex/_flush
给索引配置分析器
![image.png](https://upload-images.jianshu.io/upload_images/9967595-e17aeeda8f953a70.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
临时使用分词器
![image.png](https://upload-images.jianshu.io/upload_images/9967595-3b4dfdef9a5b8c85.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
获取文档指定信息
![image.png](https://upload-images.jianshu.io/upload_images/9967595-3f0830339931d127.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
?pretty&fields=user 只显示user字段
![image.png](https://upload-images.jianshu.io/upload_images/9967595-3f7407712179b1a7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
删除 curl -XDELETE ///
数据更新 xput
![image.png](https://upload-images.jianshu.io/upload_images/9967595-c5badaeee2c6d85e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-e5a34cb4cb634e3c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-513e0267eef33b66.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-d533ce540d148778.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
xpost + _mget? 批量获取
![image.png](https://upload-images.jianshu.io/upload_images/9967595-3716270a3e9d6bf0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
_source 获取数据
_query?q=user:xxx
--------------------------------------------------------------------------------------
信息检索:curl -XGET ip/_search?q=hello&pretty=true
terms查询:不作分词
match_all:{} 查询所有
常规查询:+ -