Python 查询 ElasticSearch 路径,带反斜杠



我正在使用 Python 的 Elastic 搜索扩展,试图查询特定路径。

这是我包装的查询:

{
"size": 1000,
 "query": {
   "filtered": {
     "filter": {
       "bool": {
         "must": [
           {
             "term": {
               "Path": "c:\myfolder\myfile.txt"
             }
           }
         ]
       }
     }
   }
 }
}

这在 kopf 插件中工作正常。

这是我的Python代码:

from elasticsearch import Elasticsearch
es = Elasticsearch(hosts=['my_server'])
index = "my_index"
query = '{"size":1000,"query":{"filtered":{"filter":{"bool":{"must":[{"term":{"Path":"c:\myfolder\myfile.txt"}}]}}}}}'
response = es.search(index=index, body=query)

由于某种原因,我收到此错误(如果没有反斜杠就不会发生):

/

usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", 第 69 行,_wrapped return func(*args, params=params, **kwargs) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/init.py", 第 530 行,在搜索中 doc_type, '_search'), params=params, body=body) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", 329路,perform_request 状态、标头、数据 = connection.perform_request(方法、URL、参数、正文、忽略=忽略、超时=超时)文件 "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http_urllib3.py", 106号线,perform_request self._raise_error(response.status, raw_data) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/base.py", 105号线,_raise_error raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) elasticsearch.exceptions.RequestError

仅当存在反斜杠时,才会发生此问题。

注意:我正在开发 Ubuntu。

提前谢谢。

尝试将"路径"更改为c:\\myfolder\\myfile.txt

相关内容

  • 没有找到相关文章

最新更新