Skip to content

Instantly share code, notes, and snippets.

@bitemyapp
Created May 23, 2012 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitemyapp/2777036 to your computer and use it in GitHub Desktop.
Save bitemyapp/2777036 to your computer and use it in GitHub Desktop.
# 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