Must_not but include some data

I am trying to do the following, exclude data that matches restricted_general_calculated = "all" unless another field(s) = something

This is the must_not

{
  "query": {
"bool": {
  "must_not": [
    {
      "terms": {
        "restricted_general_calculated": [
          "all"
        ]
      }
    }
  ],
  "must": []
}
  }
}

I then want to use this to include records even if restricted_general_calculated="all"

    {
      "nested": {
        "path": "salesRights",
        "query": {
          "nested": {
            "path": "salesRights.salesRestriction",
            "query": {
              "bool": {
                "must": [
                  {
                    "term": {
                      "salesRights.salesRestriction.salesRestrictionType": "04"
                    }
                  },
                  {
                    "match": {
                      "salesRights.salesRestriction.salesOutletName": "www.mysite.co.uk"
                    }
                  }
                ]
              }
            }
          }
        }
      }
    }

I tried various combinations but have just got myself into a muddle

Any help would be appreciated

Thanks

Grant

You need two bools then - the first has the should clause to represent the OR that is the root of your logic.
Rough structure is:

bool
    should
         field = something
         bool
            must_not
                restricted_general_calculated = all

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