Can we add parameters to the match query?

Hi everyone,

Given a match query built with hibernate search for elastic search backend, can we add raw parameters to the query being build ?

For example, a match query can look like this :

PredicateFinalStep b = fa.bool(b0 -> b0.should(matcherFuzzy.matching(criteria.getRechercheFullText()).fuzzy(FUZZY_1)).minimumShouldMatchNumber(1));

In this case, I would like to parameterize my fuzzy search, for example disabling the transposition.
I was thinking something like

PredicateFinalStep b = fa.bool(b0 -> b0.should(matcherFuzzy.matching(criteria.getRechercheFullText()).fieldParam("fuzziness", "1").fieldParam("fuzzy_transpositions", "false")).minimumShouldMatchNumber(1));

Here the list of parameters for field in a matching query :

Using a request transformer is more complex and low level.

Thank you.


Hibernate Search does not support transforming a single DSL predicate; transformation is at the request level only. If you need native features, the lowest granularity you can work on is a whole predicate.

So, without going as far as the request transformer, you can use native predicates:

JsonObject jsonObject =
        /* ... */; 
List<Book> hits = Book.class )
        .extension( ElasticsearchExtension.get() ) 
        .where( f -> f.fromJson( jsonObject ) ) 
        .fetchHits( 20 );

The result of f.fromJson is a predicate like any other, which can be mixed with other DSL predicates (e.g. in boolean predicates).

That being said, if the only thing you need is to add the fuzzy_transpositions parameter to the match predicate, you can open a ticket and send a pull request to add a S fuzzy(int maxEditDistance, int exactPrefixLength, boolean transpositions) method to (and implement it); I’ll be happy to review the PR and help you write the corresponding tests.

Thank you for your answer. In fact I anticipate a bit, I imagine complainers wanting to tune the search result relevance. Native predicates is a good starting point.
Thanks for the invitation to enrich API, but I need to find time apart from working days for this :upside_down_face:. By the way, the perimeter of the API is larger than “just” elastic search, this method would be specific I suppose.

Yes, if you use Elasticsearch-specific features, your code will only work with the Elasticsearch backend, not with the Lucene backend.