弹性查询仅接受4个字符

问题描述

我正在弹性搜索7.2版中运行术语查询,当我的查询中有4个字符时,它可以工作,并且如果我添加删除任何字符,都无法使用。

工作查询

{
"query": {
    "bool": {
        "must": [{
                "terms": {
                    "GEP_PN": ["6207"]
                }
            },{
                "match": {
                    "GEP_MN.keyword": "SKF"
                }
            }
        ]
    }
}
}

结果:

enter image description here

查询失败:

enter image description here

解决方法

它没有失败,没有找到您搜索词的结果,请注意文档中提到的terms query are not analyzed

返回在提供的文档中包含一个或多个确切术语的文档 字段。

请提供您的索引映射,如果使用text字段并且您没有使用自定义分析器,它将使用standard analyzer来拆分-上的令牌,因此您的字词查询与倒排索引中存在的标记不匹配。

请参阅analyze API的搜索字词,以解释可能的根本原因。

{
    "text" : "6207-R"
}

令牌

{
    "tokens": [
        {
            "token": "6207","start_offset": 0,"end_offset": 4,"type": "<NUM>","position": 0
        },{
            "token": "r","start_offset": 5,"end_offset": 6,"type": "<ALPHANUM>","position": 1
        }
    ]
}