How do I make a query like this?
REST API Query
{ "query": { "must_not": [ {"match": {"foreignId": 1}}, {"match": {"foreignId": 2}}, ... ] }
Kotlin code
fun searchWithExclude(foreignIdsForMustNot: List<Int>) {
val q = QueryBuilders.boolQuery()
.mustNot(QueryBuilders.matchQuery("id", foreignIdsForMustNot[0]))
.mustNot(QueryBuilders.matchQuery("id", foreignIdsForMustNot[1]))
...
}
searchWithExclude(listOf(1, 2, ...))
I would do it like this using a terms
query instead so you can simply pass the list in argument:
val q = QueryBuilders.boolQuery()
.mustNot(QueryBuilders.termsQuery("id", foreignIdsForMustNot))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.