def self.create_index_with_mappings
Tire.index Settings.elasticsearch_product_index do
create :settings => {
:number_of_shards => 1,
:number_of_replicas => 1,
:analysis => {
:filter => {
:name_ngrams => {
:side => 'front',
:type => 'edgeNGram',
:max_gram => 100,
:min_gram => 2
},
:whole_words => {
:type => 'word_delimiter',
:generate_word_parts => false,
:generate_number_parts => false,
:split_on_case_change => false,
:split_on_numerics => false,
:preserve_original => true # maybe not needed anymore with all the changes from above
}
},
:analyzer => {
:product_name => {
:filter => ['standard', 'lowercase', 'asciifolding', 'whole_words'],
:type => 'custom',
:tokenizer => 'standard'
},
:ngram_name => {
:filter => ['standard', 'lowercase', 'asciifolding', 'whole_words', 'name_ngrams'],
:type => 'custom',
:tokenizer => 'standard'
}
}
}
},
:mappings => {
:product => {
:properties => {
:_id => { :type => 'string', :analyzer => 'keyword', :include_in_all => false },
:name => { :type => 'multi_field', :fields => {
:name => {:type => 'string', :analyzer => 'product_name', :include_in_all => false},
:partial => {
:search_analyzer => 'product_name',
:index_analyzer => 'ngram_name',
:type => 'string',
:include_in_all => true,
:boost => 10
}
}
},
:followers => { :type => 'integer', :include_in_all => true},
:used_by_count => { :type => 'integer', :include_in_all => true},
:description => { :type => 'string', :analyzer => 'snowball' },
:description_manual => { :type => 'string', :analyzer => 'snowball' },
:language => { :type => 'string', :analyzer => 'keyword' }
}
}
}
end
end