DELETE /my_index2
PUT /my_index2
{
"mappings": {
"properties": {
"message": {
"type": "keyword",
"ignore_above": 5
},
"title": {
"type": "text",
"analyzer": "ik_smart"
},
"desc": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
GET /my_index2
#为了方便测试, 3 个属性都是一样的
PUT _bulk
{"index":{"_index":"my_index2","_id":"1"}}
{"message":"小米汽车", "title":"小米汽车", "desc":"小米汽车"}
{"index":{"_index":"my_index2","_id":"2"}}
{"message":"小米手机", "title":"小米手机", "desc":"小米手机"}
{"index":{"_index":"my_index2","_id":"3"}}
{"message":"小米科技有限公司", "title":"小米科技有限公司", "desc":"小米科技有限公司"}
{"index":{"_index":"my_index2","_id":"4"}}
{"message":"华为科技有限公司", "title":"华为科技有限公司", "desc":"华为科技有限公司"}
{"index":{"_index":"my_index2","_id":"5"}}
{"message":"华为", "title":"华为", "desc":"华为"}
{"index":{"_index":"my_index2","_id":"6"}}
{"message":"华为手机", "title":"华为手机", "desc":"华为手机"}
GET /my_index2/_search
{
"query": {
"match_all": {
}
}
}
#用term查询text类型,应尽量避免。“小米科技” 被分词了,所以用 term查不到数据
GET /my_index2/_search
{
"query": {
"term": {
"desc": "小米科技"
}
}
}
GET /my_index2/_search
{
"query": {
"match": {
"desc": "小米科技"
}
}
}
POST /_analyze
{
"analyzer":"ik_max_word",
"text":"小米科技"
}
#
POST /_analyze
{
"analyzer":"ik_max_word",
"text":"华为科技有限公司"
}
09-18
6317