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

查看:308
本文介绍了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天全站免登陆