Boto CloudSearch 可搜索文档数量

1 投票
1 回答
863 浏览
提问于 2025-04-18 14:40

我在想,怎么用boto来获取可搜索文档的数量呢?当我尝试这样做时:

import boto.cloudsearch
from boto.cloudsearch.domain import Domain    

conn = boto.cloudsearch.connect_to_region("us-east-1")
domain = Domain(conn, conn.describe_domains()[0])
print domain.num_searchable_docs

我得到了这个结果:

boto.exception.BotoServerError: BotoServerError: 401 Unauthorized
<ErrorResponse xmlns="http://cloudsearch.amazonaws.com/doc/2011-02-01/">
  <Error>
    <Type>Sender</Type>
    <Code>NotAuthorized</Code>
  </Error>
  <RequestId>3a8f8731-137a-11e4-9620-892c28eddd75</RequestId>
</ErrorResponse>

而且 cloudsearch2.domain.Domain 这个东西里没有 num_searchable_docs 这个字段。

1 个回答

2

根据亚马逊的CloudSearch 文档,我发现我需要把查询写成 q=matchall&q.parser=structured&size=0,所以用boto的话,可以这样写。

from boto.cloudsearch2.layer2 import Layer2

layer2 = Layer2()
domain = layer2.lookup('my-domain')
search = domain.get_search_service()
results = search.search(q='matchall', parser='structured', size=0)
return results.hits

撰写回答