我是弹性搜索新手。我使用以下库来帮助我构建搜索查询。 这是图书馆:
https://github.com/sudo-suhas/elastic-builder
我有以下代码来创建我的查询:
requestBody = elasticSearchBuilder.requestBodySearch()
.query(
elasticSearchBuilder.boolQuery()
.must(elasticSearchBuilder.multiMatchQuery(feilds, searchQuery)
.type(sortAlgorithm)
.tieBreaker(tieBreaker)
.minimumShouldMatch(searchAccuracy))
导致:
{
"bool": {
"must": {
"multi_match": {
"query": "xxxxxxxxx",
"fields": ["name", "owner", "byline_name", "head"],
"type": "best_fields",
"tie_breaker": 0.3
}
}
}
} }
现在我想添加另一个过滤器,在这个过滤器中搜索此数组中id为的文档:[10,23,34,44]。所以我正在寻找......之间或包含或......任何可以解决这个问题。任何人都可以帮助我吗?
更新
[
{
"id": "80092",
"categoryId": "43229",
"channelId": "54322",
"channelName": "xxxxxxxxxxxx",
"owner": "xxxxxxxxxxxxx",
"ownerChannel": "xxxxxxxxxxxxx",
"bylineName": "xxxxxxxxxxxxxx",
"bylinePublication": "xxxxxxxxxxxx"
}
]
答案 0 :(得分:2)
如果要对标识符执行此操作,则会有一个名为ids
的特殊查询POST http://localhost:9200/your_index/your_type/_search
Content-type: application/json
{
"query": {
"ids" : {
"values" : ["10", "23", "34", "44"]
}
}
}
对于其他字段,您可以使用terms查询。
{
"query": {
"constant_score" : {
"filter" : {
"terms" : { "otherField" : [10, 23, 34, 44]}
}
}
}
}