如果我搜索带有数字的 token ,则模糊不正确。
Dokument:
"Nice Photo S61"
给我查询结果
“不错”
但是我不会马上使用
“S6”
我没有结果
这是我的查询
GET /index1/_search
{
"query": {
"match" : {
"url1" : {
"query" : "s6",
"fuzziness": "auto",
"prefix_length": "3",
"max_expansions": 6,
"operator": "and"
}
}
}
}
这是我的索引设置:
PUT /index1/_settings
{
"settings": {
"analysis": {
"analyzer": {
"product_analyzer": {
"type": "custom",
"tokenizer": "punctuation",
"filter": [
"lowercase"
]
}
},
"tokenizer": {
"punctuation": {
"type": "pattern",
"pattern": "[-_.:~ ]"
}
}
}
},
"mappings" : {
"index1" : {
"properties" : {
"url":{
"type" :"text",
"analyzer" : "product_analyzer"
}
}
}
}
}
最佳答案
这与数字无关。
将fuzziness
设置为auto
时,意味着根据您的术语自动生成编辑距离。
AUTO
Generates an edit distance based on the length of the term. Low and high distance arguments may be optionally provided AUTO:[low],[high]. If not specified, the default values are 3 and 6, equivalent to AUTO:3,6 that make for lengths:
0..2 Must match exactly
3..5 One edit allowed
>5 Two edits allowed AUTO should generally be the preferred value for fuzziness.
和
prefix_length
The number of initial characters which will not be “fuzzified”. This helps to reduce the number of terms which must be examined. Defaults to 0.
因此,您可以将查询更改为此:
{
"query": {
"match" : {
"url1" : {
"query" : "S6",
"fuzziness": "1",
"prefix_length": "0",
"max_expansions": 6,
"operator": "and"
}
}
}
}
引用:
https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#fuzziness
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html
关于elasticsearch - ElasticSearch匹配查询数字模糊性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55273145/