# Elasticsearch fuzzy search not working properly with simpleQueryStringQuery

**URL:** https://discuss.elastic.co/t/elasticsearch-fuzzy-search-not-working-properly-with-simplequerystringquery/247182
**Category:** Elasticsearch
**Created:** [September 2, 2020, 7:31am UTC](https://discuss.elastic.co/t/elasticsearch-fuzzy-search-not-working-properly-with-simplequerystringquery/247182 "2020-09-02T07:31:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![vaibhavind](https://avatars.discourse-cdn.com/v4/letter/v/838e76/32.png) [@vaibhavind](https://discuss.elastic.co/u/vaibhavind)
#### Post date: [September 2, 2020, 7:31am UTC](https://discuss.elastic.co/t/elasticsearch-fuzzy-search-not-working-properly-with-simplequerystringquery/247182/1 "2020-09-02T07:31:06Z")

</div>

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+~);

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 2, 2020, 8:14am UTC](https://discuss.elastic.co/t/elasticsearch-fuzzy-search-not-working-properly-with-simplequerystringquery/247182/2 "2020-09-02T08:14:58Z")

</div>

Welcome!

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). 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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [September 30, 2020, 8:15am UTC](https://discuss.elastic.co/t/elasticsearch-fuzzy-search-not-working-properly-with-simplequerystringquery/247182/3 "2020-09-30T08:15:02Z")

</div>

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