gpt4 book ai didi

django - Django Rest Framework Elasticsearch :RequestError 400 parsing_exception

转载 作者:行者123 更新时间:2023-12-03 02:29:18 30 4
gpt4 key购买 nike

尝试查询符合此条件的事件文档时,出现解析异常,并且不确定是什么原因引起的。这是在我的自定义get_queryset方法中发生的。在文档 View 集中的get_query中,出现错误。

def get_queryset(self):
qs = super().get_queryset()
user = self.request.user

if hasattr(user, 'userprofile'):
user_universities = user.userprofile.universities.all().values_list("id")
user_universities_campus = user.userprofile.universities.all().values_list("main_campus__id")


query = query | Q('bool', must=[
Q('match', visibility_scope=Event.UNIVERSITY),
Q('bool', must=[
Q('terms', university__id=list(user_universities)),
Q('bool', should=[
Q('terms', university__main_campus__id=list(user_universities)),
Q('terms', university__main_campus__id=list(user_universities_campus))
])
])
])

qs = qs.query(query)
return qs

我收到此错误:
        if self.count == 0 and not self.allow_empty_first_page:
File "C:\Users\fendy\.virtualenvs\cul\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\fendy\.virtualenvs\cul\lib\site-packages\django\core\paginator.py", line 91, in count
return c()
File "C:\Users\fendy\.virtualenvs\cul\lib\site-packages\elasticsearch_dsl\search.py", line 679, in count
**self._params
File "C:\Users\fendy\.virtualenvs\cul\lib\site-packages\elasticsearch\client\utils.py", line 84, in _wrapped
return func(*args, params=params, **kwargs)
File "C:\Users\fendy\.virtualenvs\cul\lib\site-packages\elasticsearch\client\__init__.py", line 529, in count
"POST", _make_path(index, doc_type, "_count"), params=params, body=body
File "C:\Users\fendy\.virtualenvs\cul\lib\site-packages\elasticsearch\transport.py", line 358, in perform_request
timeout=timeout,
File "C:\Users\fendy\.virtualenvs\cul\lib\site-packages\elasticsearch\connection\http_urllib3.py", line 261, in perform_request
self._raise_error(response.status, raw_data)
File "C:\Users\fendy\.virtualenvs\cul\lib\site-packages\elasticsearch\connection\base.py", line 182, in _raise_error
status_code, error_message, additional_info
elasticsearch.exceptions.RequestError: RequestError(400, 'parsing_exception', '[terms] unknown token [END_ARRAY] after [university.id]')

查询字符串打印输出:
Bool(should=[Bool(must=[Match(visibility_scope=2), Bool(must=[Terms(university__id=[(42809,)]), Bool(should=[Terms(university__main_campus__id=[(42809,)]), Terms(university__main_campus__id=[(None,)])])])]), Match(visibility_scope=0)])

最佳答案

您的字符串查询应如下所示:

{
"bool": {
"should":[
"bool" : {
"must":[

{"match":{
"visibility_scope" : 2

},
"bool":{
"must":[
{
"terms": {

}
....
.....
.....

}
]
}

}
]
}
]



}

}


您可以使用查询字符串更新您的问题吗?我也许能完成。

关于django - Django Rest Framework Elasticsearch :RequestError 400 parsing_exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60355378/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com