Java elasticsearch, find by part of the work

I have small problem with Java elasticsearch (2.3.3)

TransportClient client = TransportClient.builder().build()
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
QueryBuilder qb = multiMatchQuery(
            "org", // George
            "firstname","lastname"

    ).fuzziness(Fuzziness.build(2));


    SearchResponse response = client.prepareSearch("user")
            .setQuery(qb)
            .execute()
            .get();

    for(SearchHit hit : response.getHits()){
        System.out.println(hit.getSource());
    }

By fuzziness, I can find when I did not type 2 letters.

I want it to find a user by firstname or lastname, by 3 or more letters.
I was searching for a way to do that last few hours.

In this case I need to find “George Michel” by typing just “org”, but no luck.

Thanks for help.

Source: java

Leave a Reply