Last active
September 14, 2016 01:21
-
-
Save giisyu/c6582a49e9497e82f00c to your computer and use it in GitHub Desktop.
Elasticsearch触ってみた。 ref: http://qiita.com/jooex/items/21a26e70f995e91a4e36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add | |
echo "deb http://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list | |
sudo apt-get update && sudo apt-get install elasticsearch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo /etc/init.d/elasticsearch start | |
sudo /etc/init.d/elasticsearch restart | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XGET 'localhost:9200/tutorial/_mapping/helloworld/?pretty' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST 'http://localhost:9200/tutorial/helloworld/' -d '{ "message": "Hello World! こんにちは!" ,"name" : "hoge"}' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
from elasticsearch import Elasticsearch | |
import json | |
es = Elasticsearch("localhost:9200") | |
matchstring = es.search(index="tutorial", | |
doc_type="helloworld", | |
body={ | |
"query" : { | |
"match" : { | |
"name" : "hoge" | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST 'http://localhost:9200/tutorial/helloworld/' -d '{ "message": "Hello World! こんにちは!" ,"name" : "hoge"}' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
simpleString = es.search(index="tutorial", | |
doc_type="helloworld", | |
body={ | |
"query" : { | |
"simple_query_string" :{ | |
"query" : "こんにちは", | |
"fields" : ["message"] | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
queryBool = es.search(index="tutorial", | |
doc_type="helloworld", | |
body={ | |
"query":{ | |
"bool":{ | |
"must":{ | |
"must":{ | |
"term" : { | |
"name" : "hoge" | |
} | |
}, | |
"term" : { | |
"message" : "Hello" | |
} | |
} | |
} | |
} | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
queryBool = es.search(index="tutorial", | |
doc_type="helloworld", | |
body={ | |
"query":{ | |
"bool":{ | |
"must":{ | |
"must":{ | |
"term" : { | |
"name" : "hoge" | |
} | |
}, | |
"term" : { | |
"message" : "Hello" | |
} | |
} | |
} | |
} | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo /usr/share/elasticsearch/bin/plugin install analysis-kuromoji |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XGET http://localhost:9200/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl 'localhost:9200/_cat/indices?v' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl 'localhost:9200/_cat/nodes?v' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl 'localhost:9200/_cat/health?v' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cluster.name: my-application | |
node.name: node-1 | |
index.number_of_shards: 1 | |
index.number_of_replicas: 0 | |
index.analysis.analyzer.default.type: custom | |
index.analysis.analyzer.default.tokenizer: kuromoji_tokenizer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPOST localhost:9200/tutorial -d '{ | |
"mappings" : { | |
"helloworld" : { | |
"properties" : { | |
"message" : { | |
"type" : "string" | |
}, | |
"name" : { | |
"type" : "string" | |
} | |
} | |
} | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment