Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import pyes
- import cPickle
- INDEX_NAME = "test_index"
- INDEX_TYPE = "test_type"
- def multi_field(name):
- return {
- name: {
- "type" : "string"
- },
- "untouched" : {
- "index" : "not_analyzed",
- "type": "string"
- }
- }
- conn = pyes.ES("localhost:9200", bulk_size=2000, autorefresh=True)
- # create index
- conn.delete_index_if_exists(INDEX_NAME)
- conn.create_index(INDEX_NAME)
- # create mapping
- mapping = {u'author': {"type": "multi_field", "fields": multi_field('author')}}
- conn.put_mapping(INDEX_TYPE, {'properties': mapping}, indexes=[INDEX_NAME])
- for doc in cPickle.load(open('authors.pkl')):
- doc['target'] = INDEX_TYPE
- conn.index(doc, INDEX_NAME, INDEX_TYPE, bulk=True)
- conn.refresh() # flushes bulk & refreshes all indexes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement