Boto CloudSearch可搜索文档数

时间:2014-07-24 21:36:29

标签: python boto amazon-cloudsearch

我想知道如何使用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 个答案:

答案 0 :(得分:2)

从亚马逊的CloudSearch documentation,我发现我必须将查询设为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