我正在使用 ElasticSearch (2.4) 和官方 Python 客户端来执行简单的查询。我的代码:
from elasticsearch import Elasticsearch
es_client = Elasticsearch("localhost:9200")
index = "indexName"
doc_type = "docType"
def search(query, search_size):
body = {
"fields": ["title"],
"size": search_size,
"query": {
"query_string": {
"fields": ["file.content"],
"query": query
}
}
}
response = es_client.search(index=index, doc_type=doc_type, body=body)
return response["hits"]["hits"]
search("python", 10) # Works fine.
问题是当我的查询包含不平衡的括号或方括号时。例如使用search("python {programming", 10)
ES 抛出:
elasticsearch.exceptions.RequestError: TransportError(400, u'search_phase_execution_exception', u'Failed to parse query [python {programming}]')
这是 ES 的预期行为吗?它不使用标记器来删除所有这些字符吗?
注意:这也发生在使用 Java 的我身上。