首页 > 解决方案 > Elasticsearch - 使用按查询更新在 doc_type 上给出错误

问题描述

我正在尝试使用以下方法一次更新多个文档:

    q = {
        "script": {
            "inline": "ctx._source.text.class='contact'",
            "lang": "painless"
        },
        "query": {
            "match": {
                "name": "Contact.txt"
            }
        }
    }

    es.update_by_query(body=q, doc_type='document', index='index_name')

如果字段名'name'是'Contact.txt',我想更新它'text':{'class':'contact'}

但是我收到了错误

TypeError: update_by_query() got an unexpected keyword argument 'doc_type'

类型是文档,所以我很困惑。我尝试删除争论并得到另一个错误

elasticsearch.exceptions.TransportError: TransportError(500, 'script_exception', 'runtime error')

标签: pythonelasticsearch

解决方案


好像您使用的是弹性版本 7.x。这不再需要doc_type指定,因为在 7.x 中删除了映射类型。

以下应该有效:

es.update_by_query(body=q, index='index_name')

推荐阅读