首页 > 解决方案 > Elasticsearch 查询交集

问题描述

我们正在努力解决我们正在尝试构建的查询,希望您能提供帮助

假设我们正在索引烹饪食谱,每个食谱都包含所需成分的列表。

例如:

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

一位顾客手里拿着一堆原料,想知道他可以用这些原料制作哪些食谱。

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

我们如何在弹性搜索查询中表达它?(获取所有没有客户没有的成分的食谱,在这种情况下返回“煮鸡蛋”)

为了清楚起见:

您可以假设我们只需要检查数量是否相等(不需要大于/小于等...)

请注意,我们无法索引客户,只能索引食谱

标签: elasticsearchelastic-stackelasticsearch-6elasticsearch-query

解决方案


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

提供的链接是您正在寻找的。布尔查询将允许您设置大于参数并检查所有成分是否可用。


推荐阅读