get_index doesn't return the expected information
See original GitHub issueThe 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.
I also noticed update in the Index class has the same issue.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
As @bidoubiwa said, no need to add
list_all_indexes_2
andget_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.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.