Skip to content

Instantly share code, notes, and snippets.

@mcantelon
Created May 26, 2012 02:20
Show Gist options
  • Save mcantelon/2791753 to your computer and use it in GitHub Desktop.
Save mcantelon/2791753 to your computer and use it in GitHub Desktop.
Basic PYES
from pyes import *
conn = ES('127.0.0.1:9200')
index_name = 'test4'
document_type = 'thing'
#conn.delete_index(index_name)
conn.create_index(index_name)
conn.index({
"name": "Color is blue",
}, index_name, document_type, 1)
conn.index({
"name": "Color is red",
}, index_name, document_type, 2)
conn.refresh()
q = TermQuery('name', 'color')
results = conn.search(query=q, indices=index_name)
for r in results:
print r
@mcantelon
Copy link
Author

Exact search (I think)

q = FieldQuery(FieldParameter('uuid', 'b53f4c8d-8ce9-4f8a-9b0b-6ed889e52336'))

Find all

q = FieldQuery(FieldParameter('uuid', '*'))

@mcantelon
Copy link
Author

conn.delete_index_if_exists(index_name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment