Skip to content

[BUG] Regression (3.2 -> main): Double negation is just negation #19266

@Swiddis

Description

@Swiddis

Describe the bug

We've tried to update our plugin to build on the 3.3 snapshots, but this causes integration test failures as doing two rounds of must_not(must_not(cond)) now matches not-cond, instead of cond. ref: opensearch-project/sql#4264

Related component

Search

To Reproduce

  1. Create an index with at least 2 different terms:
PUT /entity-a-idx
{
  "settings": {
    "index": {
      "number_of_shards": 2,
      "number_of_replicas": 1
    }
  },
  "mappings": {
    "properties": {
      "product": {
        "type": "text"
      }
    }
  }
}

POST entity-a-idx/_create/1
{
  "product": "Apples"
}

POST entity-a-idx/_create/2
{
  "product": "Oranges"
}
  1. Attempt to query with double-negation:
POST entity-a-idx/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "bool": {
            "must_not": {
              "match": {
                "product": "Oranges"
              }
            }
          }
        }
      ]
    }
  }
}
  1. On 3.2, this returns:
{
  // ...
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 0,
    "hits": [
      {
        "_index": "entity-a-idx",
        "_id": "2",
        "_score": 0,
        "_source": {
          "product": "Oranges"
        }
      }
    ]
  }
}

While on the latest 3.3 snapshot, this returns:

{
  // ...
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 0,
    "hits": [
      {
        "_index": "entity-a-idx",
        "_id": "1",
        "_score": 0,
        "_source": {
          "product": "Apples"
        }
      }
    ]
  }
}

Expected behavior

not(not(x)) should be equivalent to x. While this specific case is a little frivolous, it comes up enough in code generation, and it might indicate breakage for expressions that aren't as easily rewritten by hand.

Additional Details

Plugins
SQL & friends, but they're not used for the repro.

Screenshots
N/A

Host/Environment (please complete the following information):

  • OS: Linux 5.10, x86_64
  • OpenJDK 21

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    SearchSearch query, autocomplete ...etcbugSomething isn't working

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions