Python 用反斜杠查询 ElasticSearch 路径
Python query ElasticSearch path with backslash
我正在使用 Python 的弹性搜索扩展,试图查询特定路径。
这是我封装的查询:
{
"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",
line 69, in _wrapped
return func(*args, params=params, **kwargs) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/init.py",
line 530, in search
doc_type, '_search'), params=params, body=body) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py",
line 329, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout) File
"/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http_urllib3.py",
line 106, in perform_request
self._raise_error(response.status, raw_data) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/base.py",
line 105, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
elasticsearch.exceptions.RequestError
这个问题只有在有反斜杠的时候才会出现。
注意:我正在研究 Ubuntu。
提前致谢。
尝试将 "Path" 更改为 c:\\myfolder\\myfile.txt
。
我正在使用 Python 的弹性搜索扩展,试图查询特定路径。
这是我封装的查询:
{
"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", line 69, in _wrapped return func(*args, params=params, **kwargs) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/init.py", line 530, in search doc_type, '_search'), params=params, body=body) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 329, in perform_request status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/http_urllib3.py", line 106, in perform_request self._raise_error(response.status, raw_data) File "/usr/local/lib/python2.7/dist-packages/elasticsearch/connection/base.py", line 105, in _raise_error raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info) elasticsearch.exceptions.RequestError
这个问题只有在有反斜杠的时候才会出现。
注意:我正在研究 Ubuntu。
提前致谢。
尝试将 "Path" 更改为 c:\\myfolder\\myfile.txt
。