lib/sync.js
function (next) {

            // index creation options
            var body = {
                settings: {
                    number_of_shards : 3,
                    number_of_replicas : 2,
                    analysis: {
                        // analyzer definitions go here
                        analyzer: {
                            // default analyzer used for search & indexing
                            default: {
                                tokenizer: 'uax_url_email',
                                // indexing/search analysis:
                                // - trims leading/trailing whitespace
                                // - is case-insensitive
                                // - transforms non ascii characters into ascii character equivalents
                                // - splits on word/number boundaries and other delimiter rules
                                filter: [ 'trim', 'lowercase', 'asciifolding', 'word_delimiter_1' ]
                            },
                            // analyzer to use in indexing for autocomplete - we want ngrams of our data to be indexed
                            autocomplete_index: {
                                type: 'custom',
                                // use our own own ngram tokenizer
                                tokenizer: 'autocomplete_ngram',
                                filter: [ 'trim', 'lowercase', 'asciifolding', 'word_delimiter_1' ]
                            },
                            // analyzer to use in analyzing autocomplete search queries (don't generate ngrams from search queries)
                            autocomplete_search: {
                                type: 'custom',
                                tokenizer: 'keyword',
                                filter: [ 'trim', 'lowercase', 'asciifolding' ]
                            }
                        },
                        // filter definitions go here
                        filter: {
                            // custom word_delimiter filter to preserve original input as well as tokenize it
                            word_delimiter_1: {
                                type: 'word_delimiter',
                                preserve_original: true
                            }
                        },
                        // tokenizer definitions go here
                        tokenizer: {
                            // tokenizer to use for generating ngrams of our indexed data
                            autocomplete_ngram: {
                                type: 'edgeNGram',
                                // min and max ngram length
                                min_gram: 1,
                                max_gram: 50,
                                // generate ngrams that start from the front of the token only (eg. c, ca, cat)
                                side: 'front'
                            }
                        }
                    }
                }
            }

            // if non-default mapping info was defined on the schema (e.g. autocomplete), apply the mappings to the index
            body.mappings = {}
            body.mappings[options.type] = indexMap

            // console.log('mapping for', options.type, util.inspect(indexMap, true, 10, true))

            var reqOpts = {
                method: 'PUT',
                url: versionedUri,
                body: JSON.stringify(body)
            }

            if(options.auth) {
                reqOpts.auth = {
                    user: options.auth.user,
                    pass: options.auth.password,
                    sendImmediately: false
                };
            }

            // console.log('versionedUri', versionedUri)

            helpers.backOffRequest(reqOpts, function (err, res, body) {
                if (err) {
                    return cb(err)
                }

                if (!helpers.elasticsearchBodyOk(body)) {
                    var error = new Error('Unexpected index creation reply: '+util.inspect(body, true, 10, true))
                    error.body = body

                    return next(error)
                }

                return next()
            })
        }
function (next) {

            // index creation options
            var body = {
                settings: {
                    number_of_shards : 3,
                    number_of_replicas : 2,
                    analysis: {
                        // analyzer definitions go here
                        analyzer: {
                            // default analyzer used for search & indexing
                            default: {
                                tokenizer: 'uax_url_email',
                                // indexing/search analysis:
                                // - trims leading/trailing whitespace
                                // - is case-insensitive
                                // - transforms non ascii characters into ascii character equivalents
                                // - splits on word/number boundaries and other delimiter rules
                                filter: [ 'trim', 'lowercase', 'asciifolding', 'word_delimiter_1' ]
                            },
                            // analyzer to use in indexing for autocomplete - we want ngrams of our data to be indexed
                            autocomplete_index: {
                                type: 'custom',
                                // use our own own ngram tokenizer
                                tokenizer: 'autocomplete_ngram',
                                filter: [ 'trim', 'lowercase', 'asciifolding', 'word_delimiter_1' ]
                            },
                            // analyzer to use in analyzing autocomplete search queries (don't generate ngrams from search queries)
                            autocomplete_search: {
                                type: 'custom',
                                tokenizer: 'keyword',
                                filter: [ 'trim', 'lowercase', 'asciifolding' ]
                            }
                        },
                        // filter definitions go here
                        filter: {
                            // custom word_delimiter filter to preserve original input as well as tokenize it
                            word_delimiter_1: {
                                type: 'word_delimiter',
                                preserve_original: true
                            }
                        },
                        // tokenizer definitions go here
                        tokenizer: {
                            // tokenizer to use for generating ngrams of our indexed data
                            autocomplete_ngram: {
                                type: 'edgeNGram',
                                // min and max ngram length
                                min_gram: 1,
                                max_gram: 50,
                                // generate ngrams that start from the front of the token only (eg. c, ca, cat)
                                side: 'front'
                            }
                        }
                    }
                }
            }

            // if non-default mapping info was defined on the schema (e.g. autocomplete), apply the mappings to the index
            body.mappings = {}
            body.mappings[options.type] = indexMap

            // console.log('mapping for', options.type, util.inspect(indexMap, true, 10, true))

            var reqOpts = {
                method: 'PUT',
                url: versionedUri,
                body: JSON.stringify(body)
            }

            if(options.auth) {
                reqOpts.auth = {
                    user: options.auth.user,
                    pass: options.auth.password,
                    sendImmediately: false
                };
            }

            // console.log('versionedUri', versionedUri)

            helpers.backOffRequest(reqOpts, function (err, res, body) {
                if (err) {
                    return cb(err)
                }

                if (!helpers.elasticsearchBodyOk(body)) {
                    var error = new Error('Unexpected index creation reply: '+util.inspect(body, true, 10, true))
                    error.body = body

                    return next(error)
                }

                return next()
            })
        }
function ( next ) { // index creation options var body = { settings : { number_of_shards : 3 , number_of_replicas : 2 , analysis : { // analyzer definitions go here analyzer : { // default analyzer used for search & indexing default : { tokenizer : 'uax_url_email' , // indexing/search analysis: // - trims leading/trailing whitespace // - is case-insensitive // - transforms non ascii characters into ascii character equivalents // - splits on word/number boundaries and other delimiter rules filter : [ 'trim' , 'lowercase' , 'asciifolding' , 'word_delimiter_1' ] } , // analyzer to use in indexing for autocomplete - we want ngrams of our data to be indexed autocomplete_index : { type : 'custom' , // use our own own ngram tokenizer tokenizer : 'autocomplete_ngram' , filter : [ 'trim' , 'lowercase' , 'asciifolding' , 'word_delimiter_1' ] } , // analyzer to use in analyzing autocomplete search queries (don't generate ngrams from search queries) autocomplete_search : { type : 'custom' , tokenizer : 'keyword' , filter : [ 'trim' , 'lowercase' , 'asciifolding' ] } } , // filter definitions go here filter : { // custom word_delimiter filter to preserve original input as well as tokenize it word_delimiter_1 : { type : 'word_delimiter' , preserve_original : true } } , // tokenizer definitions go here tokenizer : { // tokenizer to use for generating ngrams of our indexed data autocomplete_ngram : { type : 'edgeNGram' , // min and max ngram length min_gram : 1 , max_gram : 50 , // generate ngrams that start from the front of the token only (eg. c, ca, cat) side : 'front' } } } } } // if non-default mapping info was defined on the schema (e.g. autocomplete), apply the mappings to the index body . mappings = { } body . mappings [ options . type ] = indexMap // console.log('mapping for', options.type, util.inspect(indexMap, true, 10, true)) var reqOpts = { method : 'PUT' , url : versionedUri , body : JSON . stringify ( body ) } if ( options . auth ) { reqOpts . auth = { user : options . auth . user , pass : options . auth . password , sendImmediately : false } ; } // console.log('versionedUri', versionedUri) helpers . backOffRequest ( reqOpts , function ( err , res , body ) { if ( err ) { return cb ( err ) } if ( ! helpers . elasticsearchBodyOk ( body ) ) { var error = new Error ( 'Unexpected index creation reply: ' + util . inspect ( body , true , 10 , true ) ) error . body = body return next ( error ) } return next ( ) } ) }
create an elasticsearch index, versioned with the current timestamp
create an elasticsearch index versioned with the current timestamp