索引 搜索 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 } } } }