Created
October 8, 2019 13:15
-
-
Save seandavi/857e2468ac5f4955011bfa723dab07bf to your computer and use it in GitHub Desktop.
Working with elasticsearch DSL and dynamic mappings
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
from elasticsearch import Elasticsearch | |
cli = Elasticsearch() # may need to create | |
from elasticsearch_dsl import connections | |
connections.add_connection('default',cli.client) | |
import elasticsearch_dsl as dsl | |
class Study(dsl.Document): | |
class Index: | |
name = 'sra_study-zq' | |
# update Document from mappings already in elasticsearch | |
Study._index.load_mappings() | |
# find all docs matching 'cancer' in title | |
s = Study.search() | |
y = s.query('match',title='cancer') | |
y.execute() | |
results = y.execute() | |
for i in results[0:5]: | |
print(i.title, i.accession) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment