Elasticsearch 基础教程

Elasticsearch 高级教程

Elasticsearch 插件

Elasticsearch 笔记

Elasticsearch FAQ

original icon
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.knowledgedict.com/tutorial/elasticsearch-query-exclude-ids.html

Elasticsearch(es)不匹配或排除指定的 id 列表

Elasticsearch(es) 查询语句语法详解 Elasticsearch(es) 查询语句语法详解


Elasticsearch(es)不匹配或排除指定的 id 列表可以将 ids query 放在 bool 查询 must_not 的子项里面。

解决方法

{
  "query": {
    "bool": {
      "filter": [
         ...                    <--- your other filters go here
      ],
      "must": [
         ...                    <--- your other must go here
      ],
      "must_not": [
        {
          "ids": {
            "values": [
              "id1", "id2"      <--- 不希望匹配的 id 列表放在这里
            ]
          }
        }
      ]
    }
  }
}