繁体   English   中英

如何使用GAE在Search API中获取所有记录的ID

[英]How to get all record's id in Search API using GAE

result = search.get_indexes(namespace='', offset=0, limit=999, start_index_name='f35cef2dfb9a8f34e381386ec5a1f7ee', include_start_index=True, fetch_schema=False)

但是,这里没有id / index

如何在Search API中只获取记录的id / index? 救命 !!

你可以使用get_range函数

response = index.get_range(start_id =“0”,ids_only = true)

https://developers.google.com/appengine/docs/python/search/indexclass#Index_get_range

上面的代码只会为您提供第一批doc_ids,我不得不花费数小时才能找到它。 使用以下代码获取所有doc_ids ...

from google.appengine.api import search

index = search.Index('YOUR_INDEX_NAME')
document_ids = [document.doc_id for document in index.get_range(start_id="0", ids_only=True)]
    while len(document_ids)>1:
      for doc_id in document_ids:
        print doc_id# Do whatever you want with these ID's
      document_ids = [document.doc_id for document in index.get_range(start_id=doc_id, ids_only=True)]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM