Created
May 23, 2012 18:49
-
-
Save bitemyapp/2777036 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Searching on my elasticsearch instance returns an empty list | |
class Dish(Document): | |
# ... some content removed | |
search = { u'name': {'boost': 1.0, | |
'index': 'analyzed', | |
'store': 'yes', | |
'type': u'string', | |
'term_vector' : 'with_positions_offsets'}, | |
u'venue': {'boost': 1.0, | |
'index': 'analyzed', | |
'store': 'yes', | |
'type': u'string', | |
'term_vector' : 'with_positions_offsets'}, | |
u'tags': {'store': 'yes', | |
'type': u'string', | |
'index_name':'tag'}, | |
u'_uid': {'boost': 10.0, | |
'index': 'not_analyzed', | |
'store': 'yes', | |
'type': u'string'}} | |
# Init follows: | |
def setup_test_index(): | |
global index_init | |
if not index_init: | |
index_init = True | |
try: | |
conn.delete_index("dish-index") | |
except Exception as e: | |
print "Got exception %s, ignored" % e | |
conn.create_index("dish-index") | |
mapping = models.Dish.search | |
conn.put_mapping("dish-type", {"properties":mapping}, ["dish-index"]) | |
dish = models.Dish.objects.first() | |
print dish.name | |
for key in mapping.keys(): | |
document = {} | |
if key != "_uid": | |
document[key] = dish[key] | |
else: | |
document[key] = str(dish.id) | |
conn.index(document, "dish-index", "dish-type") | |
conn.default_indices = ["dish-index"] | |
conn.refresh() | |
print [x for x in conn.search(query = TermQuery("name", "Cinnamon"))] | |
import sys; sys.stdout = sys.__stdout__; import ipdb; ipdb.set_trace() | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment