2

I work in Java with Elastic-search and want to filter data by "contains string" parameter.

For example: retrieve a list of children whose names start with 'r'.

But search query (code below) returns the list of children with names equal (not contains) to 'r'.

I've tried "r*" - no luck.

  builder.must(QueryBuilders.queryStringQuery("r*")
                .field("child_name")
                .lenient(true)
                .escape(true)
                .analyzeWildcard(false)
                .fuzziness(Fuzziness.ZERO)
                .defaultOperator(Operator.AND)
                .boost(2.0f));
    }

3 Answers 3

2

Try another type of QueryBuilder - WildcardQueryBuilder:

Implements the wildcard search query. Supported wildcards are *, which matches any character sequence (including the empty one), and ?, which matches any single character. Note this query can be slow, as it needs to iterate over many terms. In order to prevent extremely slow WildcardQueries, a Wildcard term should not start with one of the wildcards * or ?.

Example:

QueryBuilder qb = QueryBuilders.wildcardQuery("user", "k?mc*");
Sign up to request clarification or add additional context in comments.

1 Comment

Hi My problem was the .analyzeWildcard(false) and the boost(2.0f)); I changed it and now it is OK, but thanks and vote-up.
1

Finally, I found the problem by me-self. My problems were two:

.analyzeWildcard(false)
.boost(2.0f))

I change to:

.analyzeWildcard(true)
.boost(1.0f))

And it helped.

Comments

0

try with this :

enter image description here

wildcardQuery ==> some function of LIKE in database

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.