Add fuzzy query in Hibernate Search 6

Description

I am using hibernate search with Elasticsearch. The problem is i must use a fuzzy query directly instead of a match query with fuzziness options, because Elasticsearch do not allow for match query with fuzziness with Ngram token.
Reference link here.

Will there be support for fuzzy query in the future?

Activity

Show:

Yoann Rodière June 7, 2023 at 5:46 AM

Thanks, closing then, since nobody needs this. Let's reopen if someone requests it.

Nguyen Duc Thang June 6, 2023 at 3:45 PM

Thanks for replying,

Regardless, I’m not sure it will be as useful as you seem to think. From what I can see the fuzzy predicate in Elasticsearch only accepts one term, and I don’t think it performs analysis

Indeed you are correct, just tested on it and it didnt perform analysis. My previous thought was that elasticsearch fuzzy query also perform analysis on the words.

In the end , i dont think this feature request is no longer that important me.Should i close this?

Yoann Rodière June 5, 2023 at 11:39 AM

Thanks for opening this.

because Elasticsearch do not allow for match query with fuzziness with Ngram token

That seems suspicious as I wouldn’t expect the origin of tokens to matter. But as I’m not familiar with the problem, I can’t really tell for sure.

Regardless, I’m not sure it will be as useful as you seem to think. From what I can see the fuzzy predicate in Elasticsearch only accepts one term, and I don’t think it performs analysis. In general I would say fuzziness in the match/simpleQueryString predicates is more useful, but then I don’t know about your exact use case, so maybe in your specific case it isn’t? man shrugging

Will there be support for fuzzy query in the future?

There already is if you’re willing to resort to native features, i.e. to write your fuzzy predicate as JSON:

String fieldName = "title_ngram"; String term = "robot"; JsonObject fuzzyPredicate = new JsonObject(); JsonObject fieldJson = new JsonObject(); fuzzyPredicate.add("fuzzy", fieldJson); JsonObject innerJson = new JsonObject(); fieldJson.add(fieldName, fieldJson); innerJson.addProperty("value", term); innerJson.addProperty("fuzziness", 1); List<Book> hits = searchSession.search( Book.class ) .extension( ElasticsearchExtension.get() ) .where( f -> f.fromJson( fuzzyPredicate ) ) .fetchHits( 20 );

Otherwise, someone can always consider contributing the feature themself. You can look at the following PRs that added support for other predicates to get hints as to where to add code, how to test it, etc.:

Won't Do

Details

Assignee

Reporter

Priority

Created June 3, 2023 at 3:45 AM
Updated June 7, 2023 at 5:46 AM
Resolved June 7, 2023 at 5:46 AM

Flag notifications