elasticsearch

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:{}   查詢所有
常規查詢:+ -




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章