gpt4 book ai didi

python - Elasticsearch 7.0 : filter must_not query error

转载 作者:行者123 更新时间:2023-12-01 01:00:12 24 4
gpt4 key购买 nike

我在 Windows 8 计算机上使用elasticsearch-py 7.0 和elasticsearch server 7.0。

我有这个查询:

{
'size': 10000,
'query': {
'bool': {'must_not': {'filter': [{'term': {'status': 'ok'}}]}
}
}
}

映射是这样的:

  "mappings": {
"properties": {
"name": {"type": "text"},
"status": {"type": "keyword"},
"date": {"type":"date"}
}
}

它遵循 docs for boolean query 中指定的规则但它不起作用,因为它抛出语法错误:

RequestError: RequestError(400, 'parsing_exception', 'no [query] registered for [filter]')

但是,如果我删除“must_not”元素,它就会起作用:

{
'size': 10000,
'query': {
'bool': {'filter': [{'term': {'status': 'ok'}}]}
}
}

我在这里做错了什么?

最佳答案

filter

The clause (query) must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching.

must_not

The clause (query) must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned.

filtermust_not 都是 bool 查询的子句,并且以相同的方式工作。要使用 must_not,您需要删除 filter:

{
'size': 10000,
'query': {
'bool': {
'must_not': {
'term': {
'status': 'ok'
}
}
}
}
}

关于python - Elasticsearch 7.0 : filter must_not query error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55869774/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com