Elasticsearch fuzzy search not working properly with simpleQueryStringQuery

I am using ES 7.8 with dependency 7.1.1 in pom.xml with JDK 1.8. I am trying to perform the search on the whole document rather than on specific fields. So I am not using QueryBuilders.matchQuery or QueryBuilders.multiMatchQuery. This issue occurs when I try to search singular field in my searchbox whereas plural is present in ES. For instance:

I search: weird
Stored in document: weirds

No output is shown for it. This is for both the cases: QueryBuilders.simpleQueryStringQuery(text) and QueryBuilder matchQueryBuilder = QueryBuilders.queryStringQuery(text).fuzziness(Fuzziness.AUTO);


			//QueryBuilder matchQueryBuilder = QueryBuilders.simpleQueryStringQuery(text).flags();
	       QueryBuilder matchQueryBuilder = QueryBuilders.queryStringQuery(text).fuzziness(Fuzziness.AUTO);
	        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
	        sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
	        SearchRequest searchRequest = new SearchRequest();
	        SearchResponse searchResponse = client.search(searchRequest,RequestOptions.DEFAULT);
	        for(SearchHit searchHit : searchResponse.getHits().getHits()){

//Rest of the code

If I use ~ with my term or ~1 in simpleQueryStringQuery or querystringquery, it starts searching some other index stored in my local machine again which does not even have that term. And it then throws the error since the other index do not have the fields which current index have.

For further testing,I deleted that other index and perform the search on the current index.

When I removed the other index and then searched, querystringquery worked fine. But

QueryBuilder matchQueryBuilder = QueryBuilders.simpleQueryStringQuery(text+"~");

This query is still searching some other document which does not contain the text and is in the same index

And this is showing the error

QueryBuilder matchQueryBuilder = QueryBuilders.simpleQueryStringQuery(text+~);


Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.