带有多个参数的Scala Elasticsearch查询



我需要从Elasticsearch表中删除某些条目。我在文档中找不到任何提示。我也是一个Elasticsearch noob。要删除的行将由其typeowner_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的条目。

以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
}
}
]

最新更新