我需要從 Elasticsearch 表中洗掉某些條目。我在檔案中找不到任何提示。我也是 Elasticsearch 菜鳥。要洗掉的行將由其type和一個標識owner_id。是否可以deleteByQuery使用多個引數呼叫?或者有什么替代方案可以達到同樣的效果?
我正在使用這個庫:https ://github.com/sksamuel/elastic4s
表的樣子:
| id | type | owner_id | cost |
|------------------------------|
| 1 | house | 1 | 10 |
| 2 | hut | 1 | 3 |
| 3 | house | 2 | 16 |
| 4 | house | 1 | 11 |
在代碼中,它目前看起來像這樣:
deleteByQuery(someIndex, matchQuery("type", "house"))
我需要這樣的東西:
deleteByQuery(someIndex, matchQuery("type", "house"), matchQuery("owner_id", 1))
但這不起作用,因為 deleteByQuery 只接受一個查詢。
在這個例子中,它應該洗掉 id 為 1 和 4 的條目。
uj5u.com熱心網友回復:
用 JSON 和 rest API 格式解釋它,以使其更清楚。
索引 樣本檔案
put myindex/_doc/1
{
"type" : "house",
"owner_id" :1
}
put myindex/_doc/2
{
"type" : "hut",
"owner_id" :1
}
put myindex/_doc/3
{
"type" : "house",
"owner_id" :2
}
put myindex/_doc/4
{
"type" : "house",
"owner_id" :1
}
使用布爾查詢進行搜索
GET myindex/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"type": "house"
}
}
],
"filter": [
{
"term": {
"owner_id": 1
}
}
]
}
}
}
和查詢結果
"hits" : [
{
"_index" : "myindex",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.35667494,
"_source" : {
"type" : "house",
"owner_id" : 1
}
},
{
"_index" : "myindex",
"_type" : "_doc",
"_id" : "4",
"_score" : 0.35667494,
"_source" : {
"type" : "house",
"owner_id" : 1
}
}
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/446601.html
