0

Here is how I do it now:

.. .setQuery( filteredQuery( multiMatchQuery(String.format("*%s*", query), "name", "address", "phone") .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS), geoDistanceFilter("location") .distance(radius, DistanceUnit.KILOMETERS) .geoDistance(GeoDistance.PLANE) .point(latitude, longitude) ) ) ..

The issue is that it doesn't search for partial phrases or parts of words.. even with wildcards..

I found matchPhraseQuery but it seems that it works only with one field.. Is there any other way to implement such search?

nKognito
  • 6,297
  • 17
  • 77
  • 138

1 Answers1

1

Unfortunately, the multi-match doesn't support query wildcards. Instead of using multimatch, it sounds like you may want to take a look at the Query String Query, which has more pattern matching flexibility, and can be run against multiple fields. Query String is very powerful, as it provides you Lucene query language for your use. Its DSL looks like:

    {
        "query_string" : {
            "fields" : ["name", "address", "phone"],
            "query" : "*query*"
        }
    }

And In Java, something along these lines:

..
.setQuery(
   filteredQuery(
       .queryString("*test*").field("name").field("phone").field("address"),
       geoDistanceFilter("location")
             .distance(radius, DistanceUnit.KILOMETERS)
             .geoDistance(GeoDistance.PLANE)
             .point(latitude, longitude)
      )
)
..

Wildcards and pattern matching at search time are discouraged, because of their high computation cost. You should try to look at an index time solution for these fuzzy searching cases, using something like the NGram Tokenizer to produce these partial matches on the required fields. Look using different kinds of analyzers to get your a better search index, instead of trying to bend the query builders to your will.

IanGabes
  • 2,652
  • 1
  • 19
  • 27