# elastic searchローカル導入手順
0.事前準備
* brew導入済み
* javaのJDK導入済み
## elastic searchの導入
brew update
brew install elasticsearch
ln -sfv /usr/local/opt/elasticsearch/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist
http://localhost:9200に飛んでJSONが表示されればOK
## elastic-search headの導入
There are multiple ways of running elasticsearch-head.
Running with built in server
参考 https://github.com/mobz/elasticsearch-head
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start
brew install nodebrew
mkdir -p ~/.nodebrew/src
nodebrew install-binary latest
~/.bash_profileに下記を追記
export PATH=$PATH:/Users/「ユーザ名」/.nodebrew/node/v8.2.1/bin
- /usr/local/etc/elasticsearch/elasticsearch.ymlに下記を追記
http.cors.enabled: true
http.cors.allow-origin: "*"
- brew services restart elasticsearch
http://localhost:9100で見たことある画面がでればOK
## Pythonにelastic searchを導入
- pip install elasticsearch
テストコード
from elasticsearch import Elasticsearch
es = Elasticsearch("localhost:9200")
es.index(index="fruit", doc_type="test", id=1, body={"name":"apple", "color":"red"})
{u'_type': u'test', u'_id': u'1', u'created': True, u'_version': 1, u'_index': u'fruit'}
fruitインデックスが作成されてデータが格納される