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);
Code:
```
//QueryBuilder matchQueryBuilder = QueryBuilders.simpleQueryStringQuery(text).flags();
QueryBuilder matchQueryBuilder = QueryBuilders.queryStringQuery(text).fuzziness(Fuzziness.AUTO);
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(matchQueryBuilder);
sourceBuilder.from(0);
sourceBuilder.size(5);
sourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
SearchRequest searchRequest = new SearchRequest();
searchRequest.source(sourceBuilder);
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+~);