Or

How to filter when you have multiple filter requirements

Or

The or filter helps you filter for multiple conditions. Unlike other filters, the only values used here are filter_type and condition_value.

from relevanceai import Client 
client = Client()

filters = [{
    'filter_type' : 'or',
    "condition_value": [
    {
      'field' : 'price', 
      'filter_type' : 'numeric', 
      "condition":"<=", "condition_value":90
    },
    {
      'field' : 'price', 
      'filter_type' : 'numeric', 
      "condition":">=", 
      "condition_value": 150
    }
  ]}
]

filtered_data = client.datasets.documents.get_where(dataset_id, filters)

(A or B) and (C or D)

Below, we show an example of how to use 2 lists of filters with or logic.

from relevanceai import Client 
client = Client()

filter = [{
    'filter_type' : 'or',
    "condition_value": [
    {
      'field' : 'price', 
      'filter_type' : 'numeric', 
      "condition":"<=", 
      "condition_value":90
    },
    {
      'field' : 'price', 
      'filter_type' : 'numeric', 
      "condition":">=", 
      "condition_value": 150
    }
  ]},
  'filter_type' : 'or',
    "condition_value": [
    {
      'field' : 'animal', 
      'filter_type' : 'category', 
      "condition":"==", 
      "condition_value":"cat"
    },
    {
      'field' : 'animal', 
      'filter_type' : 'category', 
      "condition":"==", 
      "condition_value": "dog"
    }
  ]},
]

filtered_data = client.datasets.documents.get_where(dataset_id, filter)

(A or B or C) and D

Below, we show an example of how to use 2 lists of filters with or logic.

from relevanceai import Client 
client = Client()

filter = [{
    'filter_type' : 'or',
    "condition_value": [
    {
      'field' : 'price', 
      'filter_type' : 'numeric', 
      "condition":"<=", 
      "condition_value":90
    },
    {
      'field' : 'price', 
      'filter_type' : 'numeric', 
      "condition":">=", 
      "condition_value": 150
    },
    {
      'field' : 'value', 
      'filter_type' : 'numeric', 
      "condition":">=", 
      "condition_value": 2
    },
  ],
  {
      'field' : 'animal', 
      'filter_type' : 'category', 
      "condition":"==", 
      "condition_value":"cat"
  },
]

filtered_data = client.datasets.documents.get_where(dataset_id, filter)

Did this page help you?