Skip to main content
 首页 » 编程设计

python之弹性查询,其中字段在弹性中为空

2025年05月04日23小虾米

我正在尝试编写一个查询,它在 elastic 中搜索某个特定字段为 null。我们使用 Python Elasticsearch Client 在 python 中执行了这个查询。

查询:

{ 
    "_source": ["name"], 
    "query": { 
                "nested": { 
                    "path": "experience", 
                    "query": { 
                        "match": { 
                            "experience.resignation_date": { 
                                "query": None 
                            } 
                        } 
                    } 
                } 
            } 
} 

自从它的 python 我在查询部分使用了 None 但它抛出了这个错误。

elasticsearch.exceptions.RequestError: TransportError(400, 'parsing_exception', '[match] unknown token [VALUE_NULL] after [query]') 

请您参考如下方法:

missing 查询已弃用,您正在寻找 bool/must_not + exists

{ 
  "_source": [ 
    "name" 
  ], 
  "query": { 
    "nested": { 
      "path": "experience", 
      "query": { 
        "bool": { 
          "must_not": { 
            "exists": { 
              "field": "experience.resignation_date" 
            } 
          } 
        } 
      } 
    } 
  } 
}