# Fuzzy search query with specification

**URL:** <https://discuss.elastic.co/t/fuzzy-search-query-with-specification/92918>\
**Category:** Elasticsearch\
**Created:** [July 13, 2017, 4:10am UTC](https://discuss.elastic.co/t/fuzzy-search-query-with-specification/92918 "2017-07-13T04:10:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jafferwilson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jafferwilson/32/14379_2.png) [@jafferwilson](https://discuss.elastic.co/u/jafferwilson)\
**Post date:** [July 13, 2017, 4:10am UTC](https://discuss.elastic.co/t/fuzzy-search-query-with-specification/92918/1 "2017-07-13T04:10:19Z")

</div>

I have stored the data in the form of names and the domain. I am trying to use the fuzzy search for searching the possible name combination related to a particular domain. But I am getting many errors even after trying hard to figure out, how I can achieve what I am looking for.  
Here is what I tried:  
GET /names/\_search?pretty  
{  
"query": {  
"fuzzy" : { "name" : "aellebracht"  
},  
"match": {  
"domain" : "[box.com](http://box.com)"  
} } }  
The error is what I received like this:  
\> {

> "error": {  
> "root\_cause": [  
> {  
> "type": "parsing\_exception",  
> "reason": "[fuzzy] malformed query, expected [END\_OBJECT] but found [FIELD\_NAME]",  
> "line": 10,  
> "col": 1  
> }  
> ],  
> "type": "parsing\_exception",  
> "reason": "[fuzzy] malformed query, expected [END\_OBJECT] but found [FIELD\_NAME]",  
> "line": 10,  
> "col": 1  
> },  
> "status": 400  
> }

Kindly, help me.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [July 13, 2017, 8:49am UTC](https://discuss.elastic.co/t/fuzzy-search-query-with-specification/92918/2 "2017-07-13T08:49:48Z")

</div>

Your query has 2 clauses (a `fuzzy` and a `match`) but hasn't provided the context as to how they are combined - is it an OR or an AND in terms of Boolean logic? The solution is to wrap them in a `bool` query which provides the appropriate context.

---

<div class="post-metadata">

**Author:** ![jafferwilson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jafferwilson/32/14379_2.png) [@jafferwilson](https://discuss.elastic.co/u/jafferwilson)\
**Post date:** [July 13, 2017, 9:31am UTC](https://discuss.elastic.co/t/fuzzy-search-query-with-specification/92918/3 "2017-07-13T09:31:58Z")

</div>

the logic must be AND. Can you show the example for wrapping up the query that I have?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [July 13, 2017, 9:38am UTC](https://discuss.elastic.co/t/fuzzy-search-query-with-specification/92918/4 "2017-07-13T09:38:12Z")

</div>

You use an array of `must` clauses:

```
GET /names/_search?pretty
{
  "query": {
	"bool": {
	  "must": [
		{
		  "fuzzy": {
			"name": "aellebracht"
		  }
		},
		{
		  "match": {
			"domain": "box.com"
		  }
		}
	  ]
	}
  }
}
```

---

<div class="post-metadata">

**Author:** ![jafferwilson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jafferwilson/32/14379_2.png) [@jafferwilson](https://discuss.elastic.co/u/jafferwilson)\
**Post date:** [July 13, 2017, 12:51pm UTC](https://discuss.elastic.co/t/fuzzy-search-query-with-specification/92918/5 "2017-07-13T12:51:40Z")

</div>

Thank you for your reply..... 🙂 Hope this works for me. Let me try it.

---

<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:** [August 10, 2017, 12:52pm UTC](https://discuss.elastic.co/t/fuzzy-search-query-with-specification/92918/6 "2017-08-10T12:52:11Z")

</div>

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