ElasticSearch概述
ElasticSearch概述
支持RESTful风格
- 索引(index)相当于关系型数据库的一张表
- 映射(mapping)相当于关系型数据库中的表结构
- 文档(document)相当于关系型数据库中的字段
kibana调试工具进行调试
PUT person #创建索引
GET person #获取索引信息
PUT person/_mapping #创建映射
{
"properties":{
"name":{
"type":"keyword"
},
"age":{
"type":"integer"
}
}
}
GET person/_mapping 获取映射信息
PUT student #创建索引的时候添加映射
{
"mappings": {
"properties": {
"name":{
"type": "text"
},
"age":{
"type": "integer"
}
}
}
}
PUT person/_mapping #添加映射
{
"properties": {
"address":{
"type": "text"
}
}
}
PUT person/_doc/1 #指定id添加文档 不指定id只可以用post请求方式
{
"name":"zhangsan",
"age":20,
"address":"beijing"
}
GET person/_search #查询所有
GET person/_search #删除文档
analysis-ik中文分词器
-
中文分词器拷贝到ElasticSearch的plugins目录
-
重启elastic search
-
映射(mapping)时候字段的type为"keyword"表示不分词
-
映射(mapping)时候字段的type为"text"表示分词
PUT student #创建索引的时候添加映射 { "mappings": { "properties": { "name":{ "type": "text" }, "address":{ "type": "text", #text类型为分词 需要指定分词器 "analyzer":"ik_max_word" } } } } -
ik_smart 粗粒度分词方式
-
ik_max_word 细粒度分词方式
GET _analyze #分词为:我 爱 北京 天安门 { "analyzer": "ik_smart" , "text": "我爱北京天安门" } GET _analyze#分词为:我 爱 北京 天安门 天安 门 { "analyzer": "ik_max_word", "text": "我爱北京天安门" }
查询文档
- 词条查询:term
- 词条查询不会分析查询条件,只有当词条和查询字符完全匹配时才匹配搜索
- 全文查询:match
- 全文查询会分析查询条件,先将查询条件进行分词,然后查询,求并集

浙公网安备 33010602011771号