我有以下格式的文件:
{
"id": number
"chefId: number
"name": String,
"ingredients": List<String>,
"isSpecial": boolean
}
以下是 5 个文件的列表:
{
"id": 1,
"chefId": 1,
"name": "Roasted Potatoes",
"ingredients": ["Potato", "Onion", "Oil", "Salt"],
"isSpecial": false
},
{
"id": 2,
"chefId": 1,
"name": "Dauphinoise potatoes",
"ingredients": ["Potato", "Garlic", "Cream", "Salt"],
"isSpecial": true
},
{
"id": 3,
"chefId": 2,
"name": "Boiled Potatoes",
"ingredients": ["Potato", "Salt"],
"isSpecial": true
},
{
"id": 4,
"chefId": 3
"name": "Mashed Potatoes",
"ingredients": ["Potato", "Butter", "Milk"],
"isSpecial": false
},
{
"id": 5,
"chefId": 4
"name": "Hash Browns",
"ingredients": ["Potato", "Onion", "Egg"],
"isSpecial": false
}
我将进行搜索,其中名称字段中包含“Potatoes”。像这样:
{
"query": {
"wildcard": {
"status": {
"value": "*Potatoes*"
}
}
}
}
但我还想在返回文档时添加一些额外的标准:
是否可以在 Elasticsearch 中进行这种链接?我希望能够在单个查询中做到这一点,这样我就可以避免向我的(Java)代码添加逻辑。
您不能在一个 elasticsearch 查询中使用这种逻辑。您可以使用聚合/ post_filter 进行棘手的查询,以便在一个查询中包含您需要的所有数据,然后在您的 Java 应用程序中转换它。但是最好的方法(也是更易于维护的)是有两个查询。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句