We are struggling with a query that we are trying to build, hope you can assist ????

let’s assume we are indexing cooking recipes , each recipe contains a list of required ingredients.

for example:

[
  {
    "name": "omelet",
    "ingredients": {
      "eggs": "2",
      "butter": "1",
      "salt": "1"
    }
  },
  {
    "name": "boiled eggs",
    "ingredients": {
      "eggs": "2",
      "salt": "1"
    }
  }
]

A customer has in his hands a bunch of ingredients, and wants to know which recipes he can make with them.

{
  "ingredients": {
    "eggs": "2",
    "salt": "1",
    "honey": "1"
  }
}

How can we express it in an elasticsearch query? (get all recipes that don’t have ingredients that the customer doesn’t have, In this case return “boiled eggs”)

for clarity :

you can assume that we only need to check if the quantity is equal (no need for greater than/less than, etc…)

note that we cannot index the customer, just the recipes

2

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html

Link provided is what you are looking for. Bool query will allow you to set greater than parameters and check that all ingredients are available.

2