【问题标题】:elasticsearch-dsl: Negate a Filterelasticsearch-dsl:否定过滤器
【发布时间】:2016-04-11 21:45:34
【问题描述】:

我有这样的查询

   s = Search(using=es, index=indices)
   s = s.filter('range', 
                utctimestamp={'gte': begindateUTC, 'lte': enddateUTC})
         .filter("term",tags="foo").
         .sort("-utctimestamp")

我的问题是,如何否定过滤器?即不是foo。 以上是使用过滤器的“必须”,例如

  "filter": {
    "bool": {
      "must": [
        {
          "range": {
            "utctimestamp": {
              "from": 1460407864660,
              "to": 1460409664660
            }
          }
        },
        {
          "fquery": {
            "query": {
              "query_string": {
                "query": "_type:(\"foo\")"
              }
            },
            "_cache": true
          }
        }
      ]

我如何将“foo”位设为“不得”。

提前致谢

【问题讨论】:

    标签: elasticsearch elasticsearch-dsl


    【解决方案1】:

    您应该在must_not 子句中使用您的过滤器。

    must_not 子句不影响分数;他们唯一的目的是 排除可能已包含在内的文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-05
      相关资源
      最近更新 更多