ik_max_word
:会将文本做最细粒度的拆分ik_smart
:做最粗粒度的拆分PUT /lib
{
"mappings" : {
"user" : {
"properties" : {
"userId" : {
"type" : "integer"
},
"date":{
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"age":{
"type": "integer"
},
"name":{
"type": "text",
"analyzer": "ik_max_word" //使用IK分词器
},
"address":{
"type": "text",
"analyzer": "ik_max_word" //使用IK分词器
}
}
}
}
}
PUT /lib/user/1
{
"name":"陈加兵",
"age":22,
"date":"2012-11-11 12:00:00",
"address":"上海市松江区"
}
PUT /lib/user/2
{
"name":"郑元梅",
"age":22,
"date":"2012-11-11 12:00:00",
"address":"湖北武汉"
}
PUT /lib/user/3
{
"name":"张三",
"age":22,
"date":"2012-11-11 12:00:00",
"address":"江苏省淮安市"
}
GET lib/_analyze
{
"field": "address",
"text": "江苏省淮安市"
}
//分词结果如下:
{
"tokens": [
{
"token": "江苏省",
"start_offset": 0,
"end_offset": 3,
"type": "CN_WORD",
"position": 0
},
{
"token": "江苏",
"start_offset": 0,
"end_offset": 2,
"type": "CN_WORD",
"position": 1
},
{
"token": "省",
"start_offset": 2,
"end_offset": 3,
"type": "CN_CHAR",
"position": 2
},
{
"token": "淮安市",
"start_offset": 3,
"end_offset": 6,
"type": "CN_WORD",
"position": 3
},
{
"token": "淮安",
"start_offset": 3,
"end_offset": 5,
"type": "CN_WORD",
"position": 4
},
{
"token": "市",
"start_offset": 5,
"end_offset": 6,
"type": "CN_CHAR",
"position": 5
}
]
}
GET /lib/user/_search
{
"query": {
"match": {
"address": "江苏"
}
}
}
GET /lib/user/_search
{
"query": {
"match": {
"address": "淮安"
}
}
}
GET /lib/user/_search
{
"query": {
"term": {
"address": "淮安"
}
}
}