0

I have an OpenSearch query that contains two clauses. The first one should match a field to a mix of symbols, while the second is fully valid. It appears that the first clause is completely ignored and the results are the values that match only the second clause. My expectation is that no results would be returned, since nothing matches the clause with symbols.

For example, this query:


{
  "profile": "true",
  "query": {
    "query_string" : {
        "query" :  "field:\"\\&\""
    }   
  }
}

returns a MatchNoDocsQuery, as expected:

"profile" : {
    "shards" : [
      {
        "id" : "[...][instruments-...][0]",
        "searches" : [
          {
            "query" : [
              {
                "type" : "MatchNoDocsQuery",
                "description" : """MatchNoDocsQuery("empty BooleanQuery")""",
...

But if I AND it with a valid clause, I get results, the ones that match the valid clause:

GET instruments*/_search
{
  "profile": "true",
  "query": {
    "query_string" : {
        "query" :  "field:\"\\&\" AND field2:\"value\""
    }  
  }
}

"profile" : {
    "shards" : [
      {
        "id" : "[...][instruments-...][0]",
        "searches" : [
          {
            "query" : [
              {
                "type" : "TermQuery",
                "description" : "field2:value",
...

My expectation is that a MatchNoDocsQuery AND something results in a MatchNoDocsQuery, not the results of the something clause.

Now, I can try and eliminate the clause containing symbols, by cleaning up the values coming from user input, but this approach seems hacky and prone to miss some corner cases.

Is there any way to receive the desired MatchNoDocsQuery?

Andrei
  • 4,880
  • 23
  • 30

0 Answers0