Slide 47
Slide 47 text
elasticsearch-ruby Λͬͨ setup script ྫ
class ES!
def self.client!
@client ||= Elasticsearch::Client.new({!
url: ES.url,!
log: true!
})!
end!
end!
!
ES.client.indices.create({!
index: "index_name",!
body: {!
settings: {!
analysis: {!
filter: {!
...!
},!
tokenizer: {!
...!
},!
analyzer: {!
...!
}!
}!
}!
}!
})!
!
ES.client.indices.put_mapping({!
index: “index_name”,!
type: 'user',!
body: {!
company: {!
_id: { path: 'id' },!
_timestamp: { enabled: true, path: 'updated_at', store: true },!
_source: { enabled: true },!
_all: { enabled: true, analyzer: 'kuromoji_analyzer' },!
properties: {!
name: { type: 'string', store: true, index: 'analyzed', analyzer: 'kuromoji_analyzer' },!
. . .!
}!
}!
}!
})!
!
!
User.find_in_batches do |users|!
body = users.map do |user|!
{!
index: {!
_index: "index_name",!
_type: 'user',!
_id: user.id,!
data: user.elasticsearch_data,!
}!
}!
end!
ES.client.bulk body: body!
end!