Home > Blockchain >  How do i get the document id in Marqo?
How do i get the document id in Marqo?

Time:10-26

i added a document to marqo add_documents() but i didn't pass an id and now i am trying to get the document but i don't know what the document_id is?

Here is what my code look like:

mq = marqo.Client(url='http://localhost:8882')

mq.index("my-first-index").add_documents([
    {
        "Title": title,
        "Description": document_body
    }]
)

i tried to check whether the document got added or not but ;

no_of_docs = mq.index("my-first-index").get_stats()
print(no_of_docs)

i got;

{'numberOfDocuments': 1}

meaning it was added.

CodePudding user response:

if you don't add the "_id" as part of key/value then by default marqo will generate a random id for you, to access it you can search the document using the document's Title,

doc = mq.index("my-first-index").search(title_of_your_document, searchable_attributes=['Title'])

you should get a dictionary as the result something like this;

{'hits': [{'Description': your_description,
           'Title': title_of_your_document,
           '_highlights': relevant part of the doc,
           '_id': 'ac14f87e-50b8-43e7-91de-ee72e1469bd3',
           '_score': 1.0}],
 'limit': 10,
 'processingTimeMs': 122,
 'query': 'The Premier League'}

the part that says _id is the id of your document.

  • Related