Fuzzy search query with specification

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"
} } }
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.

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.

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

You use an array of must clauses:

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

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

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