Elasticsearch - 搜索NOT IN

时间:2017-02-06 16:14:45

标签: elasticsearch foselasticabundle

我得到了很多类似的文件:

{
   "id": 1,
   "createdBy": 1379662
   "content": "foo"
}
{
   "id": 2,
   "createdBy": 549674
   "content": "bar"
}

我试图获取createdBy不在列表中的所有文档:

{
  "post_filter":{
     "bool":{
        "must_not":[
           {
              "term":{
                 "createdBy":[
                    1379662,
                    18475
                 ]
              }
           }
        ]
     }
  },
  "query":{
     "match_all":{

     }
  }
}

但是我仍然可以通过1379662创建文档。 如果我在数组中只使用一个值,那么它的工作原理

"term":{
    "createdBy":[1379662]
}

在这个项目中使用旧版本的ES(1.7.5)。但有一个解决方案吗?

感谢您的帮助

Bouffe

1 个答案:

答案 0 :(得分:3)

使用terms代替term

{
  "post_filter":{
     "bool":{
        "must_not":[
           {
              "terms":{               <--- change this
                 "createdBy":[
                    1379662,
                    18475
                 ]
              }
           }
        ]
     }
  },
  "query":{
     "match_all":{

     }
  }
}
相关问题