1. <legend id='GAA0k'><style id='GAA0k'><dir id='GAA0k'><q id='GAA0k'></q></dir></style></legend>

    <small id='GAA0k'></small><noframes id='GAA0k'>

    <tfoot id='GAA0k'></tfoot>

    <i id='GAA0k'><tr id='GAA0k'><dt id='GAA0k'><q id='GAA0k'><span id='GAA0k'><b id='GAA0k'><form id='GAA0k'><ins id='GAA0k'></ins><ul id='GAA0k'></ul><sub id='GAA0k'></sub></form><legend id='GAA0k'></legend><bdo id='GAA0k'><pre id='GAA0k'><center id='GAA0k'></center></pre></bdo></b><th id='GAA0k'></th></span></q></dt></tr></i><div id='GAA0k'><tfoot id='GAA0k'></tfoot><dl id='GAA0k'><fieldset id='GAA0k'></fieldset></dl></div>
        <bdo id='GAA0k'></bdo><ul id='GAA0k'></ul>

      弹性搜索中的模式匹配?

      pattern matching in elastic search?(弹性搜索中的模式匹配?)

            <tbody id='7tojU'></tbody>
        1. <i id='7tojU'><tr id='7tojU'><dt id='7tojU'><q id='7tojU'><span id='7tojU'><b id='7tojU'><form id='7tojU'><ins id='7tojU'></ins><ul id='7tojU'></ul><sub id='7tojU'></sub></form><legend id='7tojU'></legend><bdo id='7tojU'><pre id='7tojU'><center id='7tojU'></center></pre></bdo></b><th id='7tojU'></th></span></q></dt></tr></i><div id='7tojU'><tfoot id='7tojU'></tfoot><dl id='7tojU'><fieldset id='7tojU'></fieldset></dl></div>
          <legend id='7tojU'><style id='7tojU'><dir id='7tojU'><q id='7tojU'></q></dir></style></legend>
          • <tfoot id='7tojU'></tfoot>
              <bdo id='7tojU'></bdo><ul id='7tojU'></ul>

                <small id='7tojU'></small><noframes id='7tojU'>

              1. 本文介绍了弹性搜索中的模式匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                继续我之前的 post,我已根据 femtoRgon 的 post 弹性搜索不支持某些字符和锚点.

                Continuing from my earlier post, I have changed the query as according to femtoRgon's post some characters and anchors are not supported by elastic search.

                我正在寻找匹配xxx-xx-xxxx"等模式的方法,以便使用 elastic search 查找带有社会安全号码的文档.

                I am looking the way to match the pattern like "xxx-xx-xxxx" in order to look for documents with social security numbers using elastic search.

                假设,在索引文档中,我想查找所有那些社会安全号码与xxx-xx-xxxx"模式匹配的文档.

                Let’s suppose, in indexed documents, I would like to find all those documents that has social security numbers that matches "xxx-xx-xxxx" pattern.

                索引文档的示例代码:

                InputStream is = null;
                    try {
                      is = new FileInputStream("/home/admin/Downloads/20121221.doc");
                      ContentHandler contenthandler = new BodyContentHandler();
                      Metadata metadata = new Metadata();
                      Parser parser = new AutoDetectParser();
                      parser.parse(is, contenthandler, metadata, new ParseContext());
                      }
                    catch (Exception e) {
                      e.printStackTrace();
                    }
                    finally {
                        if (is != null) is.close();
                    } 
                

                搜索示例代码

                QueryBuilder queryBuilderFullText = null;
                queryBuilderFullText = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
                                        FilterBuilders.regexpFilter("_all", "[0-9]{3}?[0-9]{2}?[0-9]{4}"));
                SearchRequestBuilder requestBuilder;
                            requestBuilder = client.prepareSearch()
                                    .setIndices(getDomainIndexId(project))
                                    .setTypes(getProjectTypeId(project))
                                    .setQuery(queryBuilderFullText);
                SearchResponse response = requestBuilder.execute().actionGet(ES_TIMEOUT_MS);
                            SearchHits hits = response.getHits();
                if (hits.getTotalHits() > 0) {
                System.out.println(hits.getTotalHits());
                 } else {
                                return 0l;  
                        }
                

                我因关注而受到关注:

                45-555-5462
                457-55-5462
                4578-55-5462
                457-55-54623
                457-55-5462-23
                

                但根据我的要求,它应该只返回457-55-5462"(基于模式匹配xxx-xx-xxxx").

                But as per my requirement, it should only return "457-55-5462" (based on pattern matching "xxx-xx-xxxx").

                请帮忙.

                推荐答案

                看到 ^, $d 不能用过,我会这样做:

                Seeing as ^, $ and d can't be used, I would do this:

                [^0-9-][0-9]{3}-[0-9]{2}-[0-9]{4}[^0-9-]
                

                或者在 Java 中:

                Or in Java:

                FilterBuilders.regexpFilter("_all", "[^0-9-][0-9]{3}-[0-9]{2}-[0-9]{4}[^0-9-]"));
                

                检查找到的数字之前或之后是否没有其他数字或破折号.它确实需要在匹配之前和之后有 some 字符,因此这不会捕获将社会安全号码作为 very beginningvery结束.

                Which checks that before or after the found number are no other numbers or dashes. It does require there be some character before and after the match though, so this won't capture documents that have the social security number as the very beginning or very end.

                Regex101 演示

                这篇关于弹性搜索中的模式匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)

                      <bdo id='soz89'></bdo><ul id='soz89'></ul>
                      <i id='soz89'><tr id='soz89'><dt id='soz89'><q id='soz89'><span id='soz89'><b id='soz89'><form id='soz89'><ins id='soz89'></ins><ul id='soz89'></ul><sub id='soz89'></sub></form><legend id='soz89'></legend><bdo id='soz89'><pre id='soz89'><center id='soz89'></center></pre></bdo></b><th id='soz89'></th></span></q></dt></tr></i><div id='soz89'><tfoot id='soz89'></tfoot><dl id='soz89'><fieldset id='soz89'></fieldset></dl></div>
                    • <tfoot id='soz89'></tfoot>

                      <small id='soz89'></small><noframes id='soz89'>

                    • <legend id='soz89'><style id='soz89'><dir id='soz89'><q id='soz89'></q></dir></style></legend>
                        <tbody id='soz89'></tbody>