# Word\_delimiter\_graph with pattern\_replace

**URL:** <https://discuss.elastic.co/t/word-delimiter-graph-with-pattern-replace/328736>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [March 28, 2023, 4:49pm UTC](https://discuss.elastic.co/t/word-delimiter-graph-with-pattern-replace/328736 "2023-03-28T16:49:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wonder\_Garance](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wonder_garance/32/91180_2.png) [@Wonder\_Garance](https://discuss.elastic.co/u/Wonder_Garance)\
**Post date:** [March 28, 2023, 4:49pm UTC](https://discuss.elastic.co/t/word-delimiter-graph-with-pattern-replace/328736/1 "2023-03-28T16:49:18Z")

</div>

In the settings I use the filter word\_delimiter\_graph and other filters to uniform some reference numbers, and I want to keep the original.

For these references: 01/01234 11-2-3.4.5/67/8  
I wish to get the output from conditional\_number\_word\_delimiter\_graph:  
01/01234, 01\_01234  
11-2-3.4.5/67/8, 11\_2\_3\_4\_5\_67\_8

How can I do it?

Here is my filter, at the output I get only:  
01\_01234  
11\_2\_3\_4\_5\_67\_8

```auto
      "number_word_delimiter_graph": {
        "type": "word_delimiter_graph",
        "catenate_words": false,
        "catenate_numbers": false,
        "generate_number_parts": false,
        "generate_word_parts": false,
        "split_on_case_change": false,
        "split_on_numerics": false,
        "catenate_all": false,
        "preserve_original": true,
        "adjust_offsets": true
      },
      "pattern_number_uniform": {
        "type": "pattern_replace",
        "pattern": "[.\\-/]",
        "replacement": "_"
      },
      "conditional_number_word_delimiter_graph": {
        "type": "condition",
        "filter": ["number_word_delimiter_graph", "pattern_number_uniform"],
        "script": {
          "lang": "painless",
          "source": "!token.isKeyword() && token.getTerm().toString().indexOf('%') < 0"
        }
      }

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [March 29, 2023, 1:46pm UTC](https://discuss.elastic.co/t/word-delimiter-graph-with-pattern-replace/328736/2 "2023-03-29T13:46:59Z")

</div>

Hi @Wonder_Garance

I believe the problem is the pattern\_number\_uniform filter. After you apply the number\_word\_delimiter\_graph the next filter will replace characters and with that you will have only one token.

I see that to solve this you could create a subfield where you apply the replace filter. So you have a field with the original value and a sub with the replace rule. In the search, you will apply match the two fields.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 26, 2023, 1:47pm UTC](https://discuss.elastic.co/t/word-delimiter-graph-with-pattern-replace/328736/3 "2023-04-26T13:47:04Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
