5

I have an entity named Port with a field portName. I wrote following Spring Data ES query method for containing query:

List<Port> ports = portRepository.findByPortNameContaining(searchText);

It is working fine until the searchText doesn't contain any spaces. If it does, I get the following error:

"Cannot constructQuery '*\"sample port\"*'. Use expression or multiple clauses instead."

When I try Spring Data ES search method as:

List<Port> ports = Lists.newArrayList(portRepository.search(
            queryStringQuery(searchText)
                    .field("portName")
    ));

If I have a port named Loui Kentucky, I am only able to get results when the searchText is exactly a complete word like Loui or Kentucky or Loui Kentucky. Same happens with analyzeWildcard:

List<Port> ports = Lists.newArrayList(portRepository.search(
       boolQuery().should(queryStringQuery(searchText).analyzeWildcard(true).field("portName"))
    ));

I want to construct a simple containing query which can handle spaces as well. No fuzziness. Search results should appear even when I search for i K as Loui Kentucky contains that substring.

  • ref: https://stackoverflow.com/questions/43182552/spring-data-api-containing-or-startwith-not-working-with-space-which-has-wildc – Nitin Sep 06 '19 at 10:32

0 Answers0