regex - RegEx用于匹配Lucene中的任何2个字母+任何6个数字

标签 regex elasticsearch lucene

我正在为Elastic Search中的重要术语聚合编写排除过滤器。我想从结果中排除任何与模式匹配的术语(任意2个字母)(任意6个数字),即AB123456

我试过了:

[a-zA-Z]{2}&<0-9>{6}

但是当我尝试更新可视化效果时,Kibana给出了一个错误
[x_content_parse_exception] [1:72] [significant_terms] exclude doesn't support values of type: START_OBJECT

这个JavaScript似乎可以满足我的要求:
([a-zA-Z]{2}\d{6})

但我正在努力将其翻译为Lucene

最佳答案

您在这里不需要“&”,它会尝试查找同时匹配[a-z] {2}和<0-9> {2}的标记,而不是一个接一个地匹配。

这是基于我对问题的理解的解决方案。它将排除包含2个字母后跟6个数字的文档:

PUT /stackoverflowtest/_doc/1
{
    "value" : "AB123456"
}

PUT /stackoverflowtest/_doc/2
{
    "value" : "AB1234Z"
}

PUT /stackoverflowtest/_doc/3
{
    "value" : "This document has one at the end: AB123456"
}

POST /stackoverflowtest/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "regexp": {
            "value": "[a-z]{2}<0-9>{6}"
          }
        }
      ]
    }
  }
}

这仅返回一个文档,一个文档的值为“AB1234Z”,该文档没有2个字母,后跟6个数字表示任何 token 。

关于regex - RegEx用于匹配Lucene中的任何2个字母+任何6个数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55960845/

相关文章:

elasticsearch - Logstash 和卡夫卡

hibernate - 异步搜索

ruby-on-rails - 几个非常具体的elasticsearch问题

python - 正则表达式查找带引号的字符串中的所有大括号

java - 在流上应用正则表达式来提取字符串

regex - 常规 Exp 验证 Zero 的

php - Elasticsearch PHP fatal error :未捕获的TypeError:参数1

angularjs - 使用angularjs请求Elasticsearch作为跨域

Azure 认知搜索 - 什么时候会使用不同的搜索和索引分析器?

regex - 阿富汗电话号码的正则表达式验证