mil*_*yid 9 python elasticsearch
将Python包elasticsearch从7.6.0更新到8.1.0后,我开始在这行代码中收到错误:
count = es.count(index=my_index, body={'query': query['query']} )["count"]
Run Code Online (Sandbox Code Playgroud)
收到以下错误消息:
DeprecationWarning:“body”参数已弃用,并将在未来版本中删除。而是使用单独的参数。
count = es.count(index=ums_index, body={'query': query['query']} )["count"]
我不明白如何使用上述“个别参数”。这是我的查询:
query = {
"bool": {
"must":
[
{"exists" : { "field" : 'device'}},
{"exists" : { "field" : 'app_version'}},
{"exists" : { "field" : 'updatecheck'}},
{"exists" : { "field" : 'updatecheck_status'}},
{"term" : { "updatecheck_status" : 'ok'}},
{"term" : { "updatecheck" : 1}},
{
"range": {
"@timestamp": {
"gte": from_date,
"lte": to_date,
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"
}
}
}
],
"must_not":
[
{"term" : { "device" : ""}},
{"term" : { "updatecheck" : ""}},
{"term" : { "updatecheck_status" : ""}},
{
"terms" : {
"app_version" : ['2.2.1.1', '2.2.1.2', '2.2.1.3', '2.2.1.4', '2.2.1.5',
'2.2.1.6', '2.2.1.7', '2.1.2.9', '2.1.3.2', '0.0.0.0', '']
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
在官方文档中,我找不到任何机会找到如何在新版本的 Elasticsearch 中传递查询的示例。
除了恢复到以前版本的 Elasticsearch 之外,可能有人有针对这种情况的解决方案?
Mig*_*ios 17
根据文档,现在应按如下方式完成此操作:
\n# \xe2\x9c\x85 New usage:\nes.search(query={...})\n\n# \xe2\x9d\x8c Deprecated usage:\nes.search(body={"query": {...}})\nRun Code Online (Sandbox Code Playgroud)\n因此,查询是直接在同一行代码中完成的,无需“body”,而是替换您需要使用的 api,在您的情况下,将“count”替换为“search”。\n您可以尝试以下操作:
\n# \xe2\x9c\x85 New usage:\nes.count(query={...})\n\n# \xe2\x9d\x8c Deprecated usage:\nes.count(body={"query": {...}})\nenter code here\nRun Code Online (Sandbox Code Playgroud)\n您可以点击以下链接了解更多信息:
\nhttps://github.com/elastic/elasticsearch-py/issues/1698
\n例如,如果查询是:
\nGET index-00001/_count\n{\n "query" : {\n "match_all": {\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\nPython 客户端将是下一个:
\nmy_index = "index-00001"\nquery = {\n "match_all": {\n }\n }\nhits = en.count(index=my_index, query=query)\nRun Code Online (Sandbox Code Playgroud)\n或者
\nhits = en.count(index=my_index, query={"match_all": {}})\nRun Code Online (Sandbox Code Playgroud)\n
小智 8
使用 Elasticsearch 8.4.1,通过 Python 客户端创建索引时,我收到了相同的警告。
我不得不这样:
settings = {
"number_of_shards": 2,
"number_of_replicas": 1
}
mappings = {
"dynamic": "true",
"numeric_detection": "true",
"_source": {
"enabled": "true"
},
"properties": {
"p_text": {
"type": "text"
},
"p_vector": {
"type": "dense_vector",
"dims": 768
},
}
}
es.indices.create(index=index_name, settings=settings, mappings=mappings)
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
15139 次 |
| 最近记录: |