Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

but, here not got id/index

how to get only id/index of record in Search API ? help !!

like image 908
Vijay Kumbhani Avatar asked Nov 01 '22 09:11

Vijay Kumbhani


2 Answers

The above code will only get you the first batch of doc_ids I had to spent hours to find this. Use the following code to get all 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)]
like image 109
Jino Jossy Avatar answered Nov 15 '22 08:11

Jino Jossy


you can use get_range function as

response = index.get_range(start_id="0", ids_only=True)

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

like image 33
Ashish Awasthi Avatar answered Nov 15 '22 09:11

Ashish Awasthi