对于分词器的疑问
来源:8-4 特定场景下的数据建模(二)

404_
2024-04-07
"tokenizer": {
"edge_ngram_tokenizer": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 18,
"token_chars": [
"letter",
"digit"
]
},
我们定义的这个tokenizer在分词的时候,以507245692104740864为例子。
分成5,50,507,。。。。直到507245692104740864。
然后再查询的时候使用match_phrase查询的时候,是怎么匹配上的呢?分词的时候并没有分出0864呀?
{
"match_phrase": {
"id_suffix": "0864"
}
}
写回答
1回答
-
少林码僧
2024-04-07
课程中有讲到,写入的数据的时候会增加一个字段id_suffix来存id的后四位,这样id_suffix就会被分成0,08.086,0864了
PUT order/_doc/507245692104740864?routing=1001 { "id":"507245692104740864", "id_suffix":"0864", "userid":1001, "store_id":[2], "store_name":["商品2"] }
查询的时候使用id和id_suffix字段一起搜就可以了
GET order/_search?routing=1001 { "highlight": { "fields": { "id": {}, "id_suffix": {} } }, "query": { "bool": { "must": [ { "term": { "userid": { "value": "1001" } } } ], "minimum_should_match": 1, "should": [ { "match_phrase": { "id": "0864" } }, { "match_phrase": { "id_suffix": "0864" } } ] } } }
00
相似问题