python 的 elasticsearch 模块在执行 update 的 ‘update’ API and will be removed。示例代码如下:
from elasticsearch import Elasticsearch es = Elasticsearch(['http://192.168.4.10:9200/']) data = { "title": "窗前明月光", 'url': 'http://www.xxx.com', 'date': '2021-12-29', 'number':1 } result = es.update(index='news', id=3, body={"doc": data}) print(result)
执行的时候能够正常更新。却提示:
DeprecationWarning: The ‘body’ parameter is deprecated for the ‘update’ API and will be removed in a future version. Instead use API parameters directly. See https://github.com/elastic/elasticsearch-py/issues/1698 for more information
根据提示在 https://github.com/elastic/elasticsearch-py/issues/1698 中提示到:
The parameter for APIs are deprecated body
For JSON requests each field within the top-level JSON object will become it’s own parameter of the API with full type hinting
# ✅ New usage: es.search(query={...}) # ❌ Deprecated usage: es.search(body={"query": {...}})
大概意思是:body 这个 API 的参数已被弃用,对于JSON请求,顶级JSON对象中的每个字段都将成为API自己的参数。
所以可以这样进行update
from elasticsearch import Elasticsearch es = Elasticsearch(['http://192.168.4.10:9200/']) data = { "title": "窗前明月光", 'url': 'http://www.xxx.com', 'date': '2021-12-29', 'number':1 } result = es.update(index='news', id=3, doc=data) print(result)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)