python
from elasticsearch import Elasticsearch
es = Elasticsearch(['localhost:9200'])
python
es.indices.create(index='my_index')
es.index(index='my_index', id=1, body={'title': 'example'})
python
from elasticsearch_dsl import Search
s = Search(using=es, index='my_index')
s = s.query('match', title='example')
response = s.execute()
python
s.aggs.bucket('group_by_title', 'terms', field='title.keyword')
python
from elasticsearch.helpers import bulk
actions = [
{'_index': 'my_index', '_id': 1, '_source': {'title': 'example'}},
{'_index': 'my_index', '_id': 2, '_source': {'title': 'example2'}}
]
bulk(es, actions)
python
s = s.query('match', title='example')
s = s[from_=0:size]