shawn cook
shawn cook

Reputation: 45

How to search for exact order matching of words in elasticsearch?

I need to make a match for an exact sentance. Here is the query Im using

{
    "query": {
        "match": {
            "description": "void names error"
        }
    }
}

But the above query is returning me not only the exact matching documents but also many other partial matches too. How to make an exact match of the above sentance?

Upvotes: 3

Views: 2112

Answers (2)

Vineeth Mohan
Vineeth Mohan

Reputation: 19253

Phrase query would be the best candidate here. Phrase will make sure that those tokens which are next to each other only matches.

If you want to match based on the order and want to score based on how well close they are , I would suggest span near query series.

Upvotes: 3

undefined_variable
undefined_variable

Reputation: 6218

{
    "query": {
        "match": {
            "description": "void names error",
            "type":"phrase"
        }
    }
}

More Details at Phrase Query

Upvotes: 4

Related Questions