question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

get_index doesn't return the expected information

See original GitHub issue

The get_index method in the Client returns an Index instance, however according to the documentation it should return a dictionary with the index information. In theory you could get this same information out of the Index instance, however it does not include the createdAt and updatedAt values.

client = meilisearch.Client("http://127.0.0.1:7700", "masterKey")
index = client.get_index("movies")

according to the documentation should result in index containing

{
    "uid": "movies",
    "primaryKey": "movie_id",
    "createdAt": "2019-11-20T09:40:33.711324Z",
    "updatedAt": "2019-11-20T10:16:42.761858Z"
}

however instead it contains an instance of Index so createdAt and updatedAt aren’t able to be accessed.

# this will error because there is no created_at
print(index.created_at)

# this will error because there is no updated_at
print(index.updated_at)

One possible solution would be to change the fetch_info method in the Index class to return the dictionary rather than an index object. The only place I see fetch_info getting used is in the Client’s get_index method so I can’t think of anywhere this change would break anything in this package. The only potential breaking issue I can think of is if a user is using this returned index instance as a “feature”, then it would break that code. This option would match the return value in the documentation.

def fetch_info(self):
    index_dict = self.http.get(f'{self.config.paths.index}/{self.uid}')
    self.primary_key = index_dict['primaryKey']
    return self.http.get(f'{self.config.paths.index}/{self.uid}')

Another option would be to include created_at and update_at in the __init__ of the Instance class and update the fetch_info method to set them.

class Index():
    def __init__(self):
        self.config = config
        self.http = HttpRequests(config)
        self.uid = uid
        self.primary_key = primary_key
        self.created_at = None
        self.updated_at = None

    def fetch_info(self):
        index_dict = self.http.get(f'{self.config.paths.index}/{self.uid}')
        self.primary_key = index_dict['primaryKey']
        self.created_at = index_dict.get('createdAt')
        self.updated_at = index_dict.get('updatedAt')
        return self

Then created_at and updated_at would be available in the Index

# now this works
print(index.created_at)

# this will also work
print(index.updated_at)

It’s also might be worth considering a combination of both. That way the return value for get_index would be what is expected, and all the information would be available in the Index index if it is used later.

https://github.com/meilisearch/meilisearch-python/blob/22470c47da255be3cdb6271be82a87eee54b6278/meilisearch/client.py#L67

I also noticed update in the Index class has the same issue.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
curquizacommented, May 24, 2021

As @bidoubiwa said, no need to add list_all_indexes_2 and get_one_index_2 in the docs For the moment, we need to add a wiki to show all the methods we expose that are not in the official docs.

1reaction
bidoubiwacommented, May 24, 2021

hey @sanders41 There is no need in creating new code-samples as they are linked to a specific spot in the documentation. Until we specifically need to showcase how to fetch the raw content of an index we don’t need to update this file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Indexing not returning expected value - Stack Overflow
str.find returns the index of character(s) in the string. · I do now that but the name could vary so I want to...
Read more >
[Fixed!] INDEX MATCH Not Returning Correct Value in Excel ...
This article describes 5 reasons of index match not returning the correct value & their solutions. Use the solutions to solve your problems....
Read more >
Lambda Function Input Event and Response Format
This section describes the structure of the event data that Amazon Lex provides to a Lambda function. Use this information to parse the...
Read more >
Excel INDEX function with formula examples - Ablebits
Apart from retrieving a single cell, the INDEX function is able to return an array of values from the entire row or column....
Read more >
Indexer troubleshooting guidance - Azure Cognitive Search
Indexer may show a different document count than either the data source, the index or count in your code in a point in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found