# elastic searchローカル導入手順

0.事前準備

* brew導入済み

* javaのJDK導入済み

## elastic searchの導入

  1. brew update

  2. brew install elasticsearch

  3. ln -sfv /usr/local/opt/elasticsearch/*.plist ~/Library/LaunchAgents

  4. 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

  • open http://localhost:9100/

  1. brew install nodebrew

  2. mkdir -p ~/.nodebrew/src

  3. nodebrew install-binary latest

  4. ~/.bash_profileに下記を追記

export PATH=$PATH:/Users/「ユーザ名」/.nodebrew/node/v8.2.1/bin

  1. /usr/local/etc/elasticsearch/elasticsearch.ymlに下記を追記

http.cors.enabled: true

http.cors.allow-origin: "*"

  1. brew services restart elasticsearch

http://localhost:9100で見たことある画面がでればOK

## Pythonにelastic searchを導入

  1. 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インデックスが作成されてデータが格納される

results matching ""

    No results matching ""