Skip to content

Instantly share code, notes, and snippets.

@abronner
abronner / Zero Downtime (part 1 of 3)
Created April 23, 2015 01:03
Elasticsearch-Toronto Meetup: Zero Downtime (April 21, 2015)
# ----------------------------------------------------------------------------------------------------------------
# Elasticsearch-Toronto Meetup: Zero Downtime (part 1 of 3)
# ----------------------------------------------------------------------------------------------------------------
# My presentation at the second elasticsearch meetup in Toronto
# April 21, 2015
# http://www.meetup.com/ElasticSearch-toronto
# http://www.meetup.com/Elasticsearch-Toronto/events/220384588/
# ----------------------------------------------------------------------------------------------------------------
# Demo with elasticsearch 1.5.1 and Marvel/Sense
# Installation: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_installing_elasticsearch.html
@abronner
abronner / elasticsearch-python reindex helper exmaple
Last active August 29, 2015 14:19
Elasticsearch-Toronto Meetup: Zero Downtime (April 21, 2015)
# source: https://github.com/elastic/elasticsearch-py/blob/master/elasticsearch/helpers/__init__.py
def reindex(client, source_index, target_index, query=None, target_client=None, chunk_size=500, scroll='5m', scan_kwargs={}, bulk_kwargs={}):
target_client = client if target_client is None else target_client
docs = helpers.scan(client, query=query, index=source_index, scroll=scroll, **scan_kwargs)
def _change_doc_index(hits, index):
for h in hits:
h['_index'] = index
# SOME MODIFICATION TO THE DOCUMENT:
h['_source']['first_name'] = h['_source']['username'].split()[0]
yield h
@abronner
abronner / Chapter 1: WHEN SCHEMA-LESS MET AGGREGATIONS
Last active June 20, 2016 12:50
Elasticsearch Toronto Meetup: The Power of Mapping (Jan 19, 2015)
# ----------------------------------------------------------------------------------------------------------------
# Elasticsearch-Toronto Meetup: The Power of Mapping (part 1 of 3)
# ----------------------------------------------------------------------------------------------------------------
# My presentation at the first elasticsearch meetup in Toronto
# January 19, 2015
# http://www.meetup.com/ElasticSearch-toronto
# http://www.meetup.com/Elasticsearch-Toronto/events/218903340
# ----------------------------------------------------------------------------------------------------------------
# Demo with elasticsearch 1.4.2 and Marvel/Sense
# Installation: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_installing_elasticsearch.html
@abronner
abronner / gist:10019478
Created April 7, 2014 12:35
elasticsearch (1.0.1) multi-field terms facet counts the same document twice
# reproduced with elasticsearch 1.0.1:
# index a document with 2 fields, both with the same value (the index will be implicitly generated)
curl -XPOST 'http://localhost:9200/test/test/2' -d '{
"first_name": "Rochelle",
"last_name": "Rochelle"
}'
# multi-field terms facet counts the document twice ('count = 2' for the term 'Rochelle')