Pavan kumar
Pavan kumar

Reputation: 3

How to search on all fields with partial search string in spring data elastic search

Suppose I have a word Pavan.I am able to get the data with complete word "Pavan",But when I am searching with "Pav".I am getting empty list.

Upvotes: 0

Views: 1397

Answers (1)

aditya gupta
aditya gupta

Reputation: 433

you can use queryString query ,it does full text search on all the fields or you can also specify the field in which u want to search manually please click this link for more information

@Autowired
private Client client;

   BoolQueryBuilder boolqueryBuilder = new BoolQueryBuilder();

    boolqueryBuilder.should(QueryBuilders
                    .queryStringQuery("*"+querystring+"*")
                    .defaultOperator(Operator.AND).analyzeWildcard(true));

SearchResponse response = client.prepareSearch("your index name")

                .setQuery(boolqueryBuilder).setExplain(true).get();

Upvotes: 1

Related Questions