Food Filter

The filter object refines food results based on various criteria. It supports logical operators: must (AND) and should (OR). Additionally, the mustNot operator is available to exclude foods that match specific ingredients or tags.

How to use logical operators

Use the following syntaxis ask to filter fieldName1 and FieldName2

filter: { must: [ {fieldName1: value1}, {FieldName2: value2} ] }

Use the following syntaxis ask to filter fieldName1 orFieldName2

filter: { should: [ {fieldName1: value1}, {FieldName2: value2} ] }

Add recursive filters by combining must and should operators:

filter: { should: [ {fieldName1: "value1"}, { must: [ {fieldName2: "value2"}, {fieldName3: value3} ] }] }

For example, the above example describes how to filter value1 information or value2 and value3 values. Each value can have a different field type.

mustNot Operator

Use the mustNot operator to exclude specific values from the results. It works similarly to must but filters out matching values instead of including them.

For example, to retrieve results that must include value1 but must not include value2:

filter:{ must:{ fieldName1:"value1" } mustNot:{ fieldName2:"value2" } }

Available fields

Field Name

Type

Description

id

ID

Unique ID retrieved from the brandedFoods or customFoods search queries Use this in the following:

externalID

String

Edamam o USDA unique ID, known ad foodID Use this in the following:

tags

String

Predefined tag to be added to use it to filter food. Add one or more tags. For example: tags: ["tag1", "tag2"]. Use this in the following:

mealTime

MealTime

Valid values are: BREAKFAST, LUNCH, DINNER, SNACK, TREAT_DESSERT. Use this in the recipeSearch query

nutrients

Nutrient

Valid Values: nutrient, range.

Use this in the following:

ingredients

String

Add one or more ingredients. Use this in the recipeSearch query

barcode

String

Barcode number

name

String

Food Name

Examples

How to use tags

filter: {
      tags: ["fat-free", "caffeine-free"]
 }

How to use mealTime

The following example filters the information of lunch and dinner meal times. See an example in the recipeSearch documentation.

filter: {
		must: [
			{mealTime: LUNCH},
			{mealTime: DINNER}
		]}

The following example filters the information of lunch or dinner meal times.

filter: {
		should: [
			{mealTime: LUNCH},
			{mealTime: DINNER}
		]}

How to use ingredients

The following example filters the information by milk OR bread ingredients.

 filter: {
   should: [
			{ingredients: "milk"},
			{ingredients: "bread"}
		]

How to use nutrients

The following example filters the information by food that contains Vitamin A and Folic Acid. The nutrient value can be replaced by using any of the values listed on filed name column of the the Nutrient enum table

filter: {
      nutrients: [
        {nutrient:VITAMIN_A_RAE range: {lte: 100}}
        {nutrient:FOLIC_ACID range: {gte: 10}}
      ]
    }

How to use mustNot operator

The following example filters foods that contain the ingredient potato but exclude those that contain the ingredient onion or have the tag “high-fat

filter:{
      must:{
        ingredients:"potato"
      }
    	mustNot:{
        ingredients:"onion"
        tags:"high-fat"
      }
    }

Last updated

Was this helpful?