Skip to content

Instantly share code, notes, and snippets.

@giisyu
Last active September 14, 2016 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giisyu/c6582a49e9497e82f00c to your computer and use it in GitHub Desktop.
Save giisyu/c6582a49e9497e82f00c to your computer and use it in GitHub Desktop.
Elasticsearch触ってみた。 ref: http://qiita.com/jooex/items/21a26e70f995e91a4e36
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
sudo /etc/init.d/elasticsearch start
sudo /etc/init.d/elasticsearch restart
curl -XGET 'localhost:9200/tutorial/_mapping/helloworld/?pretty'
curl -X POST 'http://localhost:9200/tutorial/helloworld/' -d '{ "message": "Hello World! こんにちは!" ,"name" : "hoge"}'
# -*- 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"
}
}
})
curl -X POST 'http://localhost:9200/tutorial/helloworld/' -d '{ "message": "Hello World! こんにちは!" ,"name" : "hoge"}'
simpleString = es.search(index="tutorial",
doc_type="helloworld",
body={
"query" : {
"simple_query_string" :{
"query" : "こんにちは",
"fields" : ["message"]
}
}
})
queryBool = es.search(index="tutorial",
doc_type="helloworld",
body={
"query":{
"bool":{
"must":{
"must":{
"term" : {
"name" : "hoge"
}
},
"term" : {
"message" : "Hello"
}
}
}
}
})
queryBool = es.search(index="tutorial",
doc_type="helloworld",
body={
"query":{
"bool":{
"must":{
"must":{
"term" : {
"name" : "hoge"
}
},
"term" : {
"message" : "Hello"
}
}
}
}
})
sudo /usr/share/elasticsearch/bin/plugin install analysis-kuromoji
curl -XGET http://localhost:9200/
curl 'localhost:9200/_cat/indices?v'
curl 'localhost:9200/_cat/nodes?v'
curl 'localhost:9200/_cat/health?v'
sudo /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
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
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