![](/img/trans.png)
[英]Is it possible to upsert documents in elasticsearch based on a given field other than _id?
[英]Elasticsearch to return documents based on 2 criteria where one is based on the other
我有以下格式的文件:
{
"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查詢中擁有這種邏輯。 您可以使用aggregations / post_filter進行棘手的查詢,以便在一個查詢中獲得所需的所有數據,然后在Java應用程序中對其進行轉換。 但是最好的方法(並且更易於維護)是有兩個查詢。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.