Simple query string query returning invalid results

I'm using the following query:

{  
   "query":{  
      "filtered":{  
         "query":{  
            "simple_query_string":{  
               "query":"subject:\"mystring\""
            }
         }
      }
   }
}

From what I understand, it should only returns records in which the subject field contains "mystring". But ES is returning all records that contains mystring in all fields.

What exactly causes that? Is it possible to change this behavior?

Hi Fernandomm,

Try this and let us know what would be the result:

{
  "query": { 
    "match": { 
      "subject": "mystring"
    }
  }
}

Regards,

Yes, in this case it works and only returns 12 results.

If i'm using simple_query_string, it returns 1627 results.

I am not familiar with the simple query string query, but I am assuming it
does not support having the field name as part of the query string, one of
the "simple" aspects. Either switch to the normal query string query, or
remove the field from the query string and explicitly place it in the field
parameter:

{
"query": {
"filtered": {
"query": {
"simple_query_string": {
"query": ""mystring"",
"fields": "subject"
}
}
}
}
}

Ivan

Hi Ivan,

You're correct. I will have to parse this manually since the normal query_string will throw exceptions if there are syntax errors.

I was trying to provide a "google like" experience for search and somehow thought that simple query search was what I needed. But without supporting search by specific fields, it's definitely not what I need.

It looks like I need something like query_string but without exceptions. Do you know if this is supported by ElasticSearch?

I would on fixing the exceptions. What are they? Formatting issues? Quotes?

It depends. Sometimes users forget to close quotes, sometimes they forget to close parentheses etc.

That's why I was looking for a way to simply ignore syntax errors since I just can't force our users to learn the query string syntax.