Elasticsearch Char filter replace all the word of that line with regex

I am trying to implement a character filter in elasticsearch that will do the task - find a word in a sentence [suppose the word is F], that sentence can be in a paragraph. it will add a prefix to all the following words [A] of [F] in the same sentence.

As an example: if the input text is "It is not good and excellent. Hello World. i do not like it." will transform into "It is not ~good ~and ~excellent. Hello World. i do not ~like ~it."

As far i am doing i can replace the immediate next word in the same line after the word [F].

My filter looks like this :

      "char_filter" : {
            "post_negs" : {
                "type" : "pattern_replace",
                "pattern" : "\\b((?i:never|no|not))\\s+(\\w*\\.|\\?|!)",
                "replacement" : "$1 ~$2"

Now how i can achieve my goal using this. TIA.


Ok, so there's a few inconsistencies that I see with your currently crafted regular expression and what you want your end result to be (referring to your example), but if I understand the gist of you're looking for, I think this should work:

\b(?!not?\b)(?!never\b)([\w-]+) replace with ~$1

Please note that the first lookahead will match both not and no.

Need Your Help

XSLT and XPath libraries for .NET Compact Framework

c# .net xslt xpath compact-framework

anybody can suggest me a library or C# code for .net compact framework 3.5 to perform XSL Transformations and/or xpath navigations?

R from java with no graphics: is it worth moving to JRI

java r jri

I have a system set up that's been happily running R from a java servlet, spawning processed & hooking into the process's stdin, stdout, and stderr streams, as in the second andwer to this ques...