我有一些看起来像这样的代码
from elasticsearch import Elasticsearch
client = Elasticsearch(hosts = [myhost])
try:
results = es_client.search(
body = {
'query' : {
'bool' : {
'must' : {
'term' : {
'foo' : 'bar',
'hello' : 'world'
}
}
}
}
},
index = 'index_A,index_B',
size = 10,
from_ = 0
)
except Exception as e:
## my code stops here, as there is an exception
import pdb
pdb.set_trace()
检查异常
SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;
再往下走
Parse Failure [Failed to parse source [{"query": {"bool": {"must": {"term": {"foo": "bar", "hello": "world"}}}}}]]]; nested: QueryParsingException[[index_A] [bool] query does not support [must]];
堆栈跟踪非常大,因此我只是摘录了它的片段,但是主要的错误似乎是不支持“必须”,至少是我构造查询的方式。
我可以发布更完整的堆栈跟踪,但是我希望有人能够看到我在“搜索”方法内的“ body”参数内犯的一个非常明显的错误。
有人能为构建python API的查询正文看到我显然做错的任何事情吗?
查询的语法对我来说似乎不正确。试试这个:
results = es_client.search(
body = {
"query": {
"bool": {
"must": [
{
"term": {
"foo": {
"value": "bar"
}
}
},
{
"term": {
"hello": {
"value": "world"
}
}
}
]
}
}
},
index = 'index_A,index_B',
size = 10,
from_ = 0
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句