Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Integrating Sphinx and Elasticsearch

Markus H
February 12, 2015

Integrating Sphinx and Elasticsearch

This is a lightning talk presentation I gave a the Python Users Berlin meetup on Feb 12, 2015

Markus H

February 12, 2015
Tweet

More Decks by Markus H

Other Decks in Programming

Transcript

  1. from elasticsearch_dsl import DocType, String class Document(DocType): title = String(analyzer='snowball',

    boost=5) body = String(analyzer='snowball') docname = String(index='not_analyzed') class Meta: index = 'docs' Elasticsearch Document
  2. import hashlib from elasticsearch_dsl.connections import connections connections.create_connection(hosts=['localhost']) def index(app, doctree,

    docname): title = app.env.titles[docname].astext() doc = Document( title=title, body=doctree.astext(), docname=docname, ) doc.id = hashlib.md5(docname.encode('utf-8')).hexdigest() doc.save() Index a Document
  3. from elasticsearch_dsl.connections import connections connections.create_connection(hosts=['localhost']) search = Document.search() query =

    search.query( 'query_string', query='Migrations', fields=['title', 'body'], ).highlight_options(order='score').highlight('body') results = query.execute() Search
  4. >>> for hit in results: ... print(hit.title) Writing database migrations

    Writing your first Django app, part 1 Django documentation FAQ: Databases and models System check framework ... Using the hits