<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Pattern Replace Character Filter 原文鏈接 : [https://www.elastic.co/guide/en/elasticsearch/reference/5.3/analysis-pattern-replace-charfilter.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/analysis-pattern-replace-charfilter.html) 譯文鏈接 :[http://www.apache.wiki/display/Elasticsearch/Pattern+Replace+Character+Filter](http://www.apache.wiki/display/Elasticsearch/Pattern+Replace+Character+Filter) 貢獻者 : [謝雄](/display/~xiexiong),[ApacheCN](/display/~apachecn),[Apache中文網](/display/~apachechina) **Pattern Replace Character Filter** 使用正則表達式來匹配應替換為指定替換字符串的字符。替換字符串可以引用正則表達式中的捕獲組。 ## 小心"病態"正則表達式 **Pattern Replace Character Filter**使用[Java正則表達式](http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)。 一個“病態”的正則表達式可能會運行得非常慢,甚至會拋出一個**StackOverflowError**,還會導致其運行的節點突然退出。 ?更多信息請查看 [pathological regular expressions and how to avoid them](http://www.regular-expressions.info/catastrophic.html)[.](http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html) ## 配置 **Pattern Replace Character Filter** 會接收以下參數: | 參數名稱 | 參數說明 | | --- | --- | | `pattern` | 一個[Java正則表達式](http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html). 必填 | | `replacement` | 替換字符串,可以使用$ 1 .. $ 9語法來引用捕獲組,可以參考[這里](http://docs.oracle.com/javase/8/docs/api/java/util/regex/Matcher.html#appendReplacement-java.lang.StringBuffer-java.lang.String-)。 | | `flags` | Java正則表達式[標志](http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html#field.summary)。 標志應該用“&#124;”進行分割,例如“CASE_INSENSITIVE &#124; COMMENTS”。 | 在下面例子中,我們使用**Pattern Replace Character Filter**實現用下劃線替代任何嵌入的破折號,即123-456-789→123_456_789: **案例** ``` PUT my_index { "settings": { "analysis": { "analyzer": { "my_analyzer": { "tokenizer": "standard", "char_filter": [ "my_char_filter" ] } }, "char_filter": { "my_char_filter": { "type": "pattern_replace", "pattern": "(\\d+)-(?=\\d)", "replacement": "$1_" } } } } } POST my_index/_analyze { "analyzer": "my_analyzer", "text": "My credit card is 123-456-789" } ``` 上面案例將返回如下結果: ``` [ My, credit, card, is 123_456_789 ] ``` 出于搜索目的使用替換字符串,會引起原始文本長度的更改,進而導致不正確的高亮顯示。案例如下所示。 這個案例在遇到小寫字母后跟大寫字母(即fooBarBaz→foo Bar Baz)時插入空格,允許單獨查詢camelCase字詞: **案例** ``` PUT my_index { "settings": { "analysis": { "analyzer": { "my_analyzer": { "tokenizer": "standard", "char_filter": [ "my_char_filter" ], "filter": [ "lowercase" ] } }, "char_filter": { "my_char_filter": { "type": "pattern_replace", "pattern": "(?<=\\p{Lower})(?=\\p{Upper})", "replacement": " " } } } }, "mappings": { "my_type": { "properties": { "text": { "type": "text", "analyzer": "my_analyzer" } } } } } POST my_index/_analyze { "analyzer": "my_analyzer", "text": "The fooBarBaz method" } ``` 案例返回的結果如下: ``` [ the, foo, bar, baz, method ] ``` 查詢 **bar** 可以正確找到文檔,但突出顯示結果將產生不正確的高光,因為我們的字符過濾器更改了原始文本的長度: ``` PUT my_index/my_doc/1?refresh { "text": "The fooBarBaz method" } GET my_index/_search { "query": { "match": { "text": "bar" } }, "highlight": { "fields": { "text": {} } } } ``` 以上的輸出結果是: ``` { "timed_out": false, "took": $body.took, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1, "max_score": 0.2824934, "hits": [ { "_index": "my_index", "_type": "my_doc", "_id": "1", "_score": 0.2824934, "_source": { "text": "The fooBarBaz method" }, "highlight": { "text": [ "The foo<em>Ba</em>rBaz method" ] } } ] } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看