Elasticsearch 过滤结果,按 id 排除 [英] Elasticsearch filter results excluding by id

查看:28
本文介绍了Elasticsearch 过滤结果,按 id 排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要返回不包含具有特定 ID 的文档的结果.Elasticsearch 允许我们指定允许使用哪些 id,但我认为没有办法禁止某些 id.就我而言,我不想返回用户已经看过的东西,因此每个用户的列表都会有所不同.

I need to return results that do not include docs with certain ids. Elasticsearch allows us to specify which ids are allowed but I see no way to disallow certain ids. In my case I want to not return things the user has already seen so the list will be different for each user.

推荐答案

您可以通过添加一个 bool/must_not 过滤器来实现此目的,该过滤器包含一个 ids 过滤器和一个数组你不想出现的id,像这样:

You can achieve this by adding a bool/must_not filter containing an ids filter with an array of ids you don't want to appear, like this:

{
  "query": {
    "bool": {
      "must": [
         ...                    <--- your other filters go here
      ],
      "must_not": [
        {
          "ids": {
            "values": [
              "id1", "id2"      <--- add all the ids you DON'T want in here
            ]
          }
        }
      ]
    }
  }
}

这篇关于Elasticsearch 过滤结果,按 id 排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆