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

      <legend id='ETBls'><style id='ETBls'><dir id='ETBls'><q id='ETBls'></q></dir></style></legend>

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

          <bdo id='ETBls'></bdo><ul id='ETBls'></ul>
        <tfoot id='ETBls'></tfoot>
      2. 弹性搜索中的模式匹配?

        时间:2023-09-29

      3. <tfoot id='44sQx'></tfoot>

        <small id='44sQx'></small><noframes id='44sQx'>

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

            <bdo id='44sQx'></bdo><ul id='44sQx'></ul>

                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 演示

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

                  上一篇:显示来自 Lucene 搜索结果的示例文本 下一篇:在 Java api 中的 Solr 搜索中需要搜索的文本和围绕

                  相关文章

                  最新文章

                  <tfoot id='ndD5O'></tfoot>

                    1. <i id='ndD5O'><tr id='ndD5O'><dt id='ndD5O'><q id='ndD5O'><span id='ndD5O'><b id='ndD5O'><form id='ndD5O'><ins id='ndD5O'></ins><ul id='ndD5O'></ul><sub id='ndD5O'></sub></form><legend id='ndD5O'></legend><bdo id='ndD5O'><pre id='ndD5O'><center id='ndD5O'></center></pre></bdo></b><th id='ndD5O'></th></span></q></dt></tr></i><div id='ndD5O'><tfoot id='ndD5O'></tfoot><dl id='ndD5O'><fieldset id='ndD5O'></fieldset></dl></div>
                    2. <small id='ndD5O'></small><noframes id='ndD5O'>

                      <legend id='ndD5O'><style id='ndD5O'><dir id='ndD5O'><q id='ndD5O'></q></dir></style></legend>
                        <bdo id='ndD5O'></bdo><ul id='ndD5O'></ul>