1

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!

3
  • Search for coffe* instead and you should find what you want Commented Feb 23, 2018 at 8:38
  • @Val No, my idea is allowing user search: coffe for coffee. Commented Feb 23, 2018 at 9:21
  • Ok, but you can append an asterisk no matter what when you create the query. The user type coffe but you search for coffe* Commented Feb 23, 2018 at 10:24

1 Answer 1

2

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 + "*"
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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.