Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
VersionEye ES mapping
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
}
},
:analyzer => {
:product_name => {
:filter => ['standard', 'lowercase', 'asciifolding'],
:type => 'custom',
:tokenizer => 'standard'
},
:ngram_name => {
:filter => ['standard', 'lowercase', 'asciifolding', '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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment