Elasticsearch filter results excluding by id

前端 未结 1 1498
傲寒
傲寒 2021-01-18 14:42

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

相关标签:
1条回答
  • 2021-01-18 15:07

    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
                ]
              }
            }
          ]
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题