elasticsearch中关键字类型为text时如何使用term查询

How to use term query when the keyword type is text in elasticsearch

您好,当我使用术语查询搜索术语时,我已经在 elasticsearch 中为 claimnumber 字段创建了一个映射,它适用于充满数字的文本,但不适用于字母和数字的文本组合,例如适用于 "123456" 不适用于 "CL123456"

映射如下

{
  "duckcreek" : {
    "mappings" : {
      "properties" : {
        "@timestamp" : {
          "type" : "date"
        },
        "@version" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
          "claimnumber" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
          "id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "policynumber" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "url" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "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"
        }
      }
    ]