Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

search results handle no-id case poorly #59

Closed
willkg opened this issue Aug 24, 2012 · 2 comments
Closed

search results handle no-id case poorly #59

willkg opened this issue Aug 24, 2012 · 2 comments

Comments

@willkg
Copy link
Member

willkg commented Aug 24, 2012

# This errors out.

import elasticutils

elasticutils.get_es().index({'object_id': 'id2'}, 'some_object_index', 'object', id='query_hash_1')
elasticutils.get_es().index({'object_id': 'some_object_id'}, 'some_object_index', 'object', id='query_hash_2')

[a for a in elasticutils.S().filter(object_id='some_object_id').indexes('some_object_index')]



# This works.

import elasticutils

elasticutils.get_es().index({'id': 1, 'object_id': 'id2'}, 'some_object_index', 'object', id='query_hash_1')
elasticutils.get_es().index({'id': 2, 'object_id': 'some_object_id'}, 'some_object_index', 'object', id='query_hash_2')

[a for a in elasticutils.S().filter(object_id='some_object_id').indexes('some_object_index')]

What's going on is that we default to asking for at least the id field, but there is no id field. In the case where the list of fields don't exist, ES doesn't return a fields key in the result dict. Need to handle that case better.

@willkg
Copy link
Member Author

willkg commented Jan 20, 2013

The pyelasticsearch bulk_index method has an id_field argument. I'm thinking having something like that could work here, too. Perhaps:

S().id_field('object_id')

And we could add get_id_field to MappingType for typed Ss.

@willkg
Copy link
Member Author

willkg commented Jan 22, 2013

Here's some updated code that should error out:

import elasticutils

es = elasticutils.get_es(urls=['http://localhost:9200'])

es.create_index('testindex')
es.index('testindex', 'testtype', {'object_id': 'id2'}, id=1)
es.index('testindex', 'testtype', {'object_id': 'foo'}, id=2)

s = elasticutils.S().es(urls=['http://localhost:9200']).indexes('testindex').doctypes('testtype')
print s

That works now. It returns a list of DefaultMappingType objects which are dict-like and don't have anything to do with the id field.

On the Django side of things, it uses self._id which is the id field that comes back from ElasticSearch--it's not part of the source document.

I think this is all set now. Closing it out.

@willkg willkg closed this as completed Jan 22, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant