什么是ElasticSearch中的调整纯负

az31mfrm  于 2023-08-03  发布在  ElasticSearch
关注(0)|答案(2)|浏览(587)

我的dsl查询看起来像下面。

{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": [{
        "terms": {
          "field": {...}
        }],
        "adjust_pure_negative": "false";
      }
    }
  }
}

字符串
当我将标记adjust_pure_negative更改为true时,我不会得到任何记录,并且true是默认值。

c8ib6hqw

c8ib6hqw1#

不知道为什么当你把标志“adjust_pure_negative”改为true时没有记录,但是当你的ElasticSearch查询中只有一个“must-not”子句,并且“adjust_pure_negative”被设置为false时。然后,ElasticSearch将认为您希望完全不匹配任何内容[因为没有任何内容可以找到相似性]。因此,查询将不返回“must-not”子句的结果。因此,为了克服这个问题,我们将“adjust_pure_negative”设置为true。
这有点荒谬。因此,在后来的版本中,该标志被删除并硬编码为true。

iq3niunx

iq3niunx2#

当查询中包含所有“must_not”子句时,则为了获得查询结果,adjust_pure_negative需要被发送为真,

GET /sample_index/_search
{
  "from": 0,
  "size": 1,
  "query": {
    "bool": {
      "must_not": [
        {
          "bool": {
            "should": [
              {
                "bool": {
                  "must_not": [
                    {
                      "range": {
                        "modifiedTime": {
                          "from": 1690186437282,
                          "to": null
                        }
                      }
                    },
                    {
                      "range": {
                        "modifiedTime": {
                          "from": null,
                          "to": 1690186437283
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ],
      "adjust_pure_negative": false
    }
  }
}

字符串
此查询将导致0个命中,同时数据存在于索引中。当设置"adjust_pure_negative": true时,它将返回命中。
Elastic Lucene期望查询中有一些肯定子句,如果查询中没有肯定子句,Elasticsearch将使用此标志并添加must match_all子句。
来源:https://discuss.elastic.co/t/what-does-adjust-pure-negative-flag-do/92348

相关问题