Avada Kedavra
Avada Kedavra

Reputation: 53

Elasticsearch, Query String, need match string

Sorry if this question is duplicated. Because I can't find any solution in my case. And sorry again, because I'm not good at English.

I'm trying to do a query on Elasticsearch using the query string:

{
    query_string: {
        fields: ["name^10"],
        query: q
    }
}

When I search with the keyword: coffee => The data will response. But when I search with the keyword: coffe => Nothing responded.

I want to match coffe with coffee in the the database. How can I do that?

Thanks for any help!

Upvotes: 1

Views: 112

Answers (1)

Val
Val

Reputation: 217514

I suggest that you simply add an asterisk * behind what the user is typing, like below, and that should achieve what you need:

{
    query_string: {
        fields: ["name^10"],
        query: q + "*"
    }
}

Upvotes: 2

Related Questions