当关键字类型为ElasticSearch中的文本时如何使用术语查询

问题描述

嗨,当我使用术语查询搜索术语时,我已经在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"
        }
      }
    ]

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...