问题描述
嗨,当我使用术语查询来搜索术语时,我已经在elasticsearch中为Claimnumber字段创建了一个映射,它对于充满数字的文本很好用,但是对于字母和数字的文本组合却不起作用,例如对于 “ 123456” 对“ CL123456”
不起作用在下面映射
{
"duckcreek" : {
"mappings" : {
"properties" : {
"@timestamp" : {
"type" : "date"
},"@version" : {
"type" : "text","fields" : {
"keyword" : {
"type" : "keyword","ignore_above" : 256
}
}
},"claimnumber" : {
"type" : "text","id" : {
"type" : "text","policynumber" : {
"type" : "text","url" : {
"type" : "text","ignore_above" : 256
}
}
}
}
}
}
}
为数字服务
GET duckcreek/_search
{
"query": {
"term": {
"claimnumber": {
"value": "99520"
}
}
}
}
不带数字的文本
GET duckcreek/_search
{
"query": {
"term": {
"claimnumber": {
"value": "CL123456"
}
}
}
}
请提出解决方案吗?
解决方法
使用Analyze API对文本字符串进行分析时
GET /_analyze
{
"analyzer" : "standard","text" : "CL123456"
}
生成的令牌为:
{
"tokens": [
{
"token": "cl123456","start_offset": 0,"end_offset": 8,"type": "<ALPHANUM>","position": 0
}
]
}
搜索查询
{
"query": {
"term": {
"title.keyword": { <-- note this
"value": "CL123456"
}
}
}
}
搜索结果
"hits": [
{
"_index": "matchprase1","_type": "_doc","_id": "2","_score": 0.6931471,"_source": {
"title": "CL123456"
}
}
]