elasticsearch - 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"
}
}
我们如何在弹性搜索查询中表达它?(获取所有没有客户没有的成分的食谱,在这种情况下返回“煮鸡蛋”)
为了清楚起见:
您可以假设我们只需要检查数量是否相等(不需要大于/小于等...)
请注意,我们无法索引客户,只能索引食谱
解决方案
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
提供的链接是您正在寻找的。布尔查询将允许您设置大于参数并检查所有成分是否可用。
推荐阅读
- python - Pandas function for removing every other value based on other dataframe
- python - How to find minimum vertices that connect certain vertices to each other
- python - How to implementing neural networks for logic gates?
- c# - I'm creating terrain that overlaps while it isn't supposed to
- python - Why does Visual Studio Code use global python config despite pointing to my virtual environment?
- java - Base Activity extending Activity ViewBinding Crash
- python - Python / Selenium / Beautiful Soup not scraping desired elements
- c++ - Custom Compare Function for Priority Queue
- git - Merge git repo branch (with different history) into master branch
- java - 如何在一对多关系中处理 Thymeleaf 和 Spring 中的表单?