2

I have the following data set:

[
  {
    "name": "Name 1",
    "countries": [
      "AF", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "UM", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CK", "CR", "HR", "CU", "CY", "CZ", "DK", "DJ", "DM", "DO", "TP", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "FX", "GF"
    ]
  },
  {
    "name": "Name 2",
    "countries": [
      "US", "GB"
    ]
  }
]

How can I filter items which DO NOT contain certain specific countries like ["GB", "FR"].

2
  • That do not contain BOTH of them or ANY of them? Commented Mar 20, 2020 at 11:14
  • That do not contain any of them Commented Mar 20, 2020 at 15:31

1 Answer 1

4

Assuming that countries is a field of type keyword, the below query should return items which do not contain ANY of the countries.

{
  "query": {
    "bool": {
      "must_not": [
        {
          "terms": {
            "countries": [
              "GB",
              "FR"
            ]
          }
        }
      ]
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.