要不要也来分享分享一下啊

es设置ik_smart分析器,但查询时失效,求解!!!!

Elasticsearch | 作者 wwwlk | 发布于2020年12月27日 | 阅读数:2009

index索引创建语句:
POST /tt1/_doc
{
"mappings": {
"properties": {
"my_id": {"type": "integer"},
"my_word": {"type": "text", "analyzer": "ik_smart", "search_analyzer": "ik_smart"},
"content": {"type": "string", "index": "not_analyzed"}
}
}
}

查询语句:
GET tt1/_search
{
"explain": true,
"query": {
"match":{
"my_word":"手机"
}
}
}

查询结果:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.5753642,
"hits" : [
{
"_shard" : "[tt1][0]",
"_node" : "T9tf-ctRTduPD3s7pXtQ_g",
"_index" : "tt1",
"_type" : "_doc",
"_id" : "nflMpHYBFFwrTE533f07",
"_score" : 0.5753642,
"_source" : {
"my_word" : "我用户手机是华为的,但我喜欢苹果"
},
"_explanation" : {
"value" : 0.5753642,
"description" : "sum of:",
"details" : [
{
"value" : 0.2876821,
"description" : "weight(my_word:手 in 0) [PerFieldSimilarity], result of:",
"details" : [
{
"value" : 0.2876821,
"description" : "score(freq=1.0), product of:",
"details" : [
{
"value" : 2.2,
"description" : "boost",
"details" : [ ]
},
{
"value" : 0.2876821,
"description" : "idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
"details" : [
{
"value" : 1,
"description" : "n, number of documents containing term",
"details" : [ ]
},
{
"value" : 1,
"description" : "N, total number of documents with field",
"details" : [ ]
}
]
},
{
"value" : 0.45454544,
"description" : "tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
"details" : [
{
"value" : 1.0,
"description" : "freq, occurrences of term within document",
"details" : [ ]
},
{
"value" : 1.2,
"description" : "k1, term saturation parameter",
"details" : [ ]
},
{
"value" : 0.75,
"description" : "b, length normalization parameter",
"details" : [ ]
},
{
"value" : 15.0,
"description" : "dl, length of field",
"details" : [ ]
},
{
"value" : 15.0,
"description" : "avgdl, average length of field",
"details" : [ ]
}
]
}
]
}
]
},
{
"value" : 0.2876821,
"description" : "weight(my_word:机 in 0) [PerFieldSimilarity], result of:",
"details" : [
{
"value" : 0.2876821,
"description" : "score(freq=1.0), product of:",
"details" : [
{
"value" : 2.2,
"description" : "boost",
"details" : [ ]
},
{
"value" : 0.2876821,
"description" : "idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
"details" : [
{
"value" : 1,
"description" : "n, number of documents containing term",
"details" : [ ]
},
{
"value" : 1,
"description" : "N, total number of documents with field",
"details" : [ ]
}
]
},
{
"value" : 0.45454544,
"description" : "tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
"details" : [
{
"value" : 1.0,
"description" : "freq, occurrences of term within document",
"details" : [ ]
},
{
"value" : 1.2,
"description" : "k1, term saturation parameter",
"details" : [ ]
},
{
"value" : 0.75,
"description" : "b, length normalization parameter",
"details" : [ ]
},
{
"value" : 15.0,
"description" : "dl, length of field",
"details" : [ ]
},
{
"value" : 15.0,
"description" : "avgdl, average length of field",
"details" : [ ]
}
]
}
]
}
]
}
]
}
}
]
}
}
可以看到手机还是分为手 和 机分别索引到的
已邀请:

FFFrp

赞同来自:

你用iksmart分一下查询的这句话看下是什么样的

wangzehao

赞同来自:

感觉是索引创建出了问题,下面是我的语句,试验是成功的(ES版本2.3.4)

微信图片_20201229134618.png

 

xiaowuge - 90后

赞同来自:

PUT /test { "settings": { "number_of_shards": 1 }, "mappings": { "properties": { "field1": { "type": "text" } } } }
 创建索引使用PUT

要回复问题请先登录注册