索引 搜索 mapping 分詞器
1.創建索引
http://192.168.65.131:9200/smartom_index?pretty
2.查看索引:
http://192.168.65.131:9200/_cat/indices?v
3.插入數據【這樣也就是說創建了一個文檔為users】
http://192.168.65.131:9200/smartom_index/users/101
{
"name":"smartom",
"age":19
}
4.精確搜索
http://192.168.65.131:9200/smartom_index/_search?q=name:smartom
5.全詞搜索
http://192.168.65.131:9200/smartom_index/_search
全文索引
6.全詞搜索 term
term是代表完全匹配,即不進行分詞器分析,文檔中必須包含整個搜索的詞匯
GET smartom_index/users/_search
{
"query":{ "term":{ "name":{ "value":"smartom" } } } }
7.全詞搜索 match 全文搜索查詢
分詞查詢
GET smartom_index/users/_search
{
"query": { "match": { "name": "我是smartom你是誰" } } }
分詞器analyze
8.創建一個分詞器
POST _analyze { "analyzer":"standard", "text":"我是smartom你是誰" }
standard
simple
過濾器 標記器
9. 一個標記器【filter?】
POST _analyze { "tokenizer":"lowercase", "text":"SMARTOM" }
也可以 在tokenizer里面寫 standard
10.一個過濾器:
POST _analyze { "tokenizer": "standard", "filter": ["lowercase"], "text": "我是smartom你是誰" }
11.字符過濾器:[過濾html代碼]
POST _analyze { "tokenizer": "standard", "char_filter": ["html_strip"], "text": "woshi<br><b>asdf</b>是" }
12.創建一個過濾器:settings analysis analyzer
PUT smartom
{
"settings": { "analysis": { "analyzer": { "smartom-analyer":{ "type":"custom", "tokenizer":"standard", "char_filter":["html_strip"], "filter":["lowercase"] } } } } }
13.創建倉庫:
前提指定repo路徑 elasticsearch.yml path.repo path.repo:["/home/smartom/Desktop/esbak"]
PUT _snapshot/mybackup
{
"type": "fs", "settings": { "location": "/home/smartom/Desktop/esbak" } }
14.備份索引:
bak1 是備份名稱 smartom_index 備份的索引名稱
PUT _snapshot/mybackup/bak1?wait_for_completion=true { "indices": "smartom_index" }
15.刪除索引
DELETE smartom
16.關閉索引
POST smartom_index/_close
17.恢復索引
POST _snapshot/mybackup/bak1/_restore?wait_for_completion=true { "indices": "smartom_index" }
18.查看當前插件
GET _cat/plugins
19.查看mapping當前文檔 查看文檔字段類型?
GET smartom_index/_mappings
20.創建mapping
[剛創建的時候]
POST /smartom_index/fulltext/_mapping
{
"properties": { "content": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word" } } }
需要導入和導出數據
刪除數據之后 title 用ik分詞器進行索引
PUT smartom_index
{
"mappings": { "news":{ "properties": { "title": { "type":"text", "analyzer": "ik_max_word" } } } } }
21.修改文檔中的類型?
PUT smartom_index/_mapping/users
{
"properties": { "news": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } }