Hibernate Search 6.1.4.Final + Elasticsearch 7.16.3, simpleQueryString flags

Thanks for the reproducer. I spent quite some time on this, and must admit I was a bit dumbfounded… until I stumbled upon this code in Lucene:

    if ("*".equals(queryText.trim())) {
      return new MatchAllDocsQuery();
    }

With any other character, you would get the behavior you want, because the text would indeed get analyzed, would be reduced to an empty list of tokens, and eventually the parsed query would be a MatchNoDocsQuery.

But you hit the one character hardcoded in the parser that triggers this behavior of matching every document.

This is Lucene, not Elasticsearch, but I’m fairly confident Elasticsearch relies on this exact parser and thus is affected the same way.

I’m afraid there isn’t much Hibernate Search can do to remove this behavior, and I suspect reporting it to Lucene/Elasticsearch won’t help, as this seems fairly intentional, although undocumented.

Maybe I should document this somewhere, though :confused:

I guess in your application, you could pre-process the query string to replace * with an empty string. But that’s about all I have to suggest.

1 Like