How to search for specific fields in a document in marqo

44 views Asked by At

i am looking for a way to search for specific fields in a document using marqo because whenever i use the .search() method the _highlights returns a random field either the title, description or any other field but it is usually random. this is an example of what i mean:

{
    'hits': [
        {   
            'Title': 'document_title',
            'Description': 'document_description',
            '_highlights': {
                'Description': 'document_description'
                               
            },
            '_id': 'document_id',
            '_score': document_score
        }, 
        {   
            'Title': 'document_title',
            'Description': "document_description",
            '_highlights': {'Title': 'document_title'},
            '_id': 'document_id',
            '_score': document_score
        }
    ],
    'limit': 10,
    'processingTimeMs': 49,
    'query': 'search_query'
}

as you can see the first documents _highlights is Description while the second is title i want a way to make it uniform.

1

There are 1 answers

0
Abubakarsq On BEST ANSWER

i think the best way of getting specific fields when using marqo is by add a keyword argument to the search method which is searchable_attributes=[] then you pass the fields you want to list as a string. eg.

result = mq.index("your_index").search('query', searchable_attributes=['Title', 'Description'])