我向marqo add_documents((添加了一个文档,但我没有传递id,现在我正在尝试获取文档,但不知道document_id是什么?
以下是我的代码:
mq = marqo.Client(url='http://localhost:8882')
mq.index("my-first-index").add_documents([
{
"Title": title,
"Description": document_body
}]
)
我试着检查文档是否被添加,但是;
no_of_docs = mq.index("my-first-index").get_stats()
print(no_of_docs)
我得到了;
{'numberOfDocuments': 1}
意味着它被添加了。
如果您不添加"_id";作为密钥/值的一部分,默认情况下marqo会为您生成一个随机id,要访问它,您可以使用文档的标题搜索文档
doc = mq.index("my-first-index").search(title_of_your_document, searchable_attributes=['Title'])
你应该得到一本字典,结果是这样的;
{'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'}
表示CCD_ 1的部分是文档的id。