liberation / django-elasticsearch

Simple wrapper around elasticsearch-py to index/search a django Model.
MIT License
211 stars 73 forks source link

Strict routing #72

Open M1ha-Shvn opened 7 years ago

M1ha-Shvn commented 7 years ago

Is there a way to fetch models with strict routing set in ElasticSearch settings? I get TransportError(400, 'RoutingMissingException[...]) When I try to call MyModel.es.get(id=100500) method

lauxley commented 7 years ago

I can't find it in the documentation ? What version of es ? What if you try with elasticsearch-py directly ?

M1ha-Shvn commented 7 years ago

I speak about this elasticsearch parameter. I used elasticsearch-py directly before starting using this library. Every request in es-py library has routing parameter, get(), for instance. But I can't specify this parameter in django-elasticsearch without modifying method in subclass, as it doesn't pass kwargs to native elasticsearch-py get() method. P. s. routing is not strict in ES by default. So requests can be done without this parameter. But our system uses strict routing, as it

can reduce the impact of searches

It is defined by mapping (I've written a subclass over ElasticsearchManager in order to define custom mapping):

"_routing": {
        "required": True,
        "path": "app_id"
},

P. p. s. Yes, I'm still using elastisearch-py directly nowadays. But to my mind, it's not good to have library (I use it for migrating databases and UnitTest purposes) and have it's part (all data fetching) not working...

lauxley commented 7 years ago

I'm not saying that you should use elasticsearch-py to do this, I'm was only trying to understand what the issue is. As you said, it's not possible for now, a quick fix would be to propagate kwargs in get() but maybe it would be better to abstract it with a routing attribute or something.