使用小的术语列表进行搜索可以得到我想要的内容
In [29]: small_list
Out[29]: [8096, 8105, 8114, 8116, 8128, 8130]
In [30]: sqs.filter(id__in=small_list)
Out[30]: [<SearchResult: web.listing (pk=u'8128')>, <SearchResult: web.listing (pk=u'8130')>, <SearchResult: web.listing (pk=u'8116')>, <SearchResult: web.listing (pk=u'8105')>, <SearchResult: web.listing (pk=u'8114')>, <SearchResult: web.listing (pk=u'8096')>]
但有成千上万的术语会出现以下错误:
In [32]: len(big_list)
Out[32]: 6305
In [33]: sqs.filter(id__in=big_list)
Traceback (most recent call last):
File "/home/ravi/bit/wonder/env/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 516, in search
_source=True)
File "/home/ravi/bit/wonder/env/local/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped
return func(*args, params=params, **kwargs)
File "/home/ravi/bit/wonder/env/local/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 530, in search
doc_type, '_search'), params=params, body=body)
File "/home/ravi/bit/wonder/env/local/lib/python2.7/site-packages/elasticsearch/transport.py", line 307, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/home/ravi/bit/wonder/env/local/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 93, in perform_request
self._raise_error(response.status, raw_data)
File "/home/ravi/bit/wonder/env/local/lib/python2.7/site-packages/elasticsearch/connection/base.py", line 105, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
RequestError: TransportError(400, u'search_phase_execution_exception')
的Django == 1.8
Django的干草堆== 2.4.1
elasticsearch == 2.1.0
答案 0 :(得分:1)
默认情况下,elasticsearch是限制为1024的查询字词的限制。
以下查询适合您
sqs.filter(id__in=big_list[:1024])
更多信息https://groups.google.com/forum/#!topic/elasticsearch/LqywKHKWbeI