java - Elasticsearch:如何调用与数组长度不一样的Java高级REST客户端

标签 java elasticsearch kotlin

如何进行这样的查询?

REST API 查询

{ "query": { "must_not": [ {"match": {"foreignId": 1}}, {"match": {"foreignId": 2}}, ...  ] } 

Kotlin 代码

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, ...))

最佳答案

我会使用 terms 查询来这样做,这样您就可以简单地在参数中传递列表:

val q = QueryBuilders.boolQuery()
    .mustNot(QueryBuilders.termsQuery("id", foreignIdsForMustNot))

关于java - Elasticsearch:如何调用与数组长度不一样的Java高级REST客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58390088/

相关文章:

android - 如何更改 RecyclerView 中特定项目的 View

java - JButton 数组返回 void

java - 如何用Java读取Excel中的特定行?

elasticsearch - 如何在 Nest for Elasticsearch 中添加完整的短语分词器?

php - Elasticsearch 按值优先排序

android - 如何等到监听器完成执行

java - 网络浏览器插件和java小程序?

java - 作为变量的 native 查询

testing - 无法为 elasticsearch 或 rabbitmq 运行 jepsen 测试

kotlin - Kotlin:高阶函数可以计算列表中的出现次数?