1

I am new in Elastic Search. I want to perform search for the pattern "Achieved by Ron@" in following string where "Achieved by" string is constant and Ron is a username that can change followed by '@' constant character:

"this is very useful, Achieved by Ron@, Let's meet sometime, Achieved to John"

I tried below query but it didn't work.

{
    "query": {
        "query_string": {
           "query": "/Achieved by .*@/"
        }
    }

}

Please help me out to solve this problem.

1 Answer 1

1

This is speculative, but the pattern .* is greedy, meaning it will consume as much text as possible before hitting the @. You may try making the dot lazy:

"query": "/Achieved by .*?@/"

If this doesn't work, perhaps because the Perl lazy dot is not supported, then another option is:

"query": "/Achieved by [^@]*@/"
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your reply. Above suggestion somewhat worked well but not completely. This is also giving false positive results where only "Achieved" word is present in String. This is returning true for "Achieved from" also.
@slayer I don't see how that could be possible, though I don't know your flavor of regex.
It is Lucene RegEx engine.
Can you give a full example of a field which is matching my answer, but which should not be?
String where I am running your answer: "I am running late, Achieved from his goal, Cool, Since you are late I'm going back". Here, it is returning true with your solution. I don't have idea how it is possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.