1

I have two users in my db collection and those names are john and john-son , now I am trying to select all records which are matching with my search text among all fields of db collection. For example my search text is john then my query is by using elasticsearch java api

QueryBuilder queryBuilderForUserSearch = QueryBuilders.must(
        QueryBuilders.fieldQuery("_all", "*" + q + "*"));

It's working fine. But when I am trying to search with special character text like john-son by this time it returns zero records. Can anybody please help me why it's happens and please provide the query for select text with special characters also.

1 Answer 1

1

The problem you have is largely the same as in this question: Elasticsearch wildcard search on not_analyzed field

First, you really don't want to have leading wildcards in your query. Lucene will have to go through every term in your index's dictionary to find terms. This is O(n) in the number of terms, which gets prohibitively expensive. See this article for more details: http://www.found.no/foundation/elasticsearch-from-the-bottom-up/

What's probably happening here is that john-son is tokenized to john and son via the standard-analyzer. Therefore, there is no john-son term in the dictionary for your wildcard query to match.

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.