Shay Banon
Lucene ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ
Lucene ๊ฒ์ ์์ง์ ์ ์ด์ฉํ๋ ์ ํ์ ๋๋ค.
๊ฒฝ์์ ํ Solr, Tica
Java 8(jdk 1.8) ์ด์ ํ์
http.cors.enabled: true
http.cors.allow-origin: "*"
# "*"์ผ ๊ฒฝ์ฐ ๋ชจ๋ ๋๋ฉ์ธ ์ ์ ๊ฐ๋ฅํ๊ธฐ ๋๋ฌธ์, ๋ณด์ ํด์ ์ ๊ฐ์
git clone https://github.com/mobz/elasticsearch-head.git
npm install locally -g
nohup locally -p 9100 &
http://localhost:9100/_plugin/head
bin/plugin install {org}/{user/component}/{version}
bin/plugin install mobz/elasticsearch-head
bin/plugin install royrusso/elasticsearch-HQ
RDB | Elasticsearch |
---|---|
Database | Index |
Table | Type |
Record | Document |
Column | Field |
Schema | Mapping |
Function | Elasticsearch HTTP method |
SQL |
---|---|---|
Create | POST | INSERT |
Read | GET | SELECT |
Update | PUT | UPDATE |
Delete | DELETE | DELETE |
curl -XPOST http://localhost:9200/books/book/1 -d '
{
"title" : "elasticsearch guide",
"author" : "Kim",
"date" : "2016-05-22",
"pages" : 250
}
'
curl -XGET http://localhost:9200/books/book/1
# ๋๋
curl -XGET http://localhost:9200/books/book/1\?pretty
curl -XPOST http://localhost:9200/books/book/1 -d '
{
"title" : "elasticsearch guide",
"author" : ["Kim", "Heo"],
"date" : "2016-05-22",
"pages" : 300
}
'
curl -XDELETE http://localhost:9200/books/book/1
_bulk
API){ "delete" : { "_index" : "books", "_type" : "book", "_id" : "1" } }
{ "update" : { "_index" : "books", "_type" : "book", "_id" : "2" } }
{ "doc" : { "date" : "2014-05-01" } }
{ "create" : { "_index" : "books", "_type" : "book", "_id" : "3" } }
{ "title" : "Elasticsearch Guide II", "author" : "Park", "pages" : 400 }
curl -XPOST http://localhost:9200/_bulk?pretty --data-binary @data.txt
curl localhost:9200/_cat/indices?v
curl -O https://codeload.github.com/wikibook/elasticsearch/zip/master
git clone https://github.com/wikibook/elasticsearch
#๋ฐ์ดํฐ ์ ์ฌ
cd elasticsearch/cd 05.๊ฒ์
curl -XPOST http://localhost:9200/_bulk --data-binary @5_1_books.json
curl -XPOST http://localhost:9200/_bulk --data-binary @5_2_magazines.json
curl localhost:9200/books/book/_search?q=keyword
curl 'localhost:9200/books,magazines/_search?q=time&pretty'
curl 'localhost:9200/_all/_search?q=time&pretty'
curl 'localhost:9200/_search?q=time&pretty'
q
curl 'localhost:9200/_search?q=title:time&pretty'
curl 'localhost:9200/_search?q=title:time%20AND%20machine&pretty'
df
(default field)curl 'localhost:9200/_search?q=time&df=title&pretty'
default_operator
curl 'localhost:9200/_search?q=time%20machine&default_operator=AND&pretty'
explain
curl 'localhost:9200/_search?q=title:time&explain&pretty'
_source
curl 'localhost:9200/_search?q=title:time&_source=false&pretty'
fields
curl 'localhost:9200/_search?q=title:time&fields=title,author,category&pretty'
sort
curl 'localhost:9200/_search?q=author:jules&sort=pages&pretty'
curl 'localhost:9200/_search?q=author:jules&sort=pages:desc&pretty'
curl 'localhost:9200/_search?q=author:jules&fields=author,title&sort=title&pretty'
curl 'localhost:9200/_search?q=author:jules&fields=author,title&sort=title:desc&pretty'
not_analyzed
๋ก ๋งคํ(mapping)ํด์ผ ํจ(8์ฅ ์ฐธ๊ณ )from
curl 'localhost:9200/_search?q=author:jules&fields=author,title&from=1&pretty'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"term" : { "author" : "william" }
}
}'
# ๋๋
curl 'localhost:9200/books/_search?pretty' -d '
{
'query' : {
'term' : { "author" : "william" }
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"from" : 1,
"size" : 2,
"stored_fields" : ["title", "category"],
"query" : {
"term" : { "author" : "william" }
}
}'
sort
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html
_source
curl 'localhost:9200/books/_search?pretty' -d '
{
"_source" : false,
"query" : {
"term" : { "author" : "william" }
}
}'
- fields
curl 'localhost:9200/magazines/_search?pretty' -d '
{
"_source" : [ "title", "c*" ]
}'
- `include`, `exclude`
curl 'localhost:9200/magazines/_search?pretty' -d '
{
"_source" : {
"include" : "c*"
}
}'
# exclude
curl 'localhost:9200/magazines/_search?pretty' -d '
{
"_source" : {
"include" : "c*",
"exclude" : "*ry"
}
}'
curl -XPUT http://localhost:9200/hotels/ -d '
{
"mappings" : {
"hotel" : {
"properties" : {
"name" : { "type" : "string"},
"stars" : { "type" : "long"},
"rooms" : { "type" : "long"},
"location" : { "type" : "geo_point"},
"city" : { "type" : "string"},
"address" : { "type" : "string"},
"internet" : { "type" : "boolean"},
"service" : { "type" : "string", "index" : "not_analyzed"},
"checkin" : { "type" : "date", "format" : "dateOptionalTime"}
}
}
}
}'
๋งคํ ์ ์ฉํ ํ์ ๋ฐ์ดํฐ ์ ์ฌ
curl -XPOST localhost:9200/_bulk --data-binary @6_1_hotels.json
์ต์๊ฐ
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"price_min" : {
"min" : { "field" : "price" }
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"price_max" : {
"max" : { "field" : "price" }
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"price_sum" : {
"sum" : { "field" : "price" }
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"price_avg" : {
"avg" : { "field" : "price" }
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"price_cnt" : {
"value_count" : { "field" : "price" }
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"price_stats" : {
"stats" : { "field" : "price" }
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"price_ex_stats" : {
"extended_stats" : { "field" : "price" }
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"query" : {
"term" : { "name" : "seoul" }
},
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"query" : {
"term" : { "name" : "seoul" }
},
"aggs" : {
"all_price" : {
"global" : {},
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"filter_name" : {
"filter" : {
"term" : { "name" : "seoul" }
},
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"missing_service" : {
"missing" : { "field" : "service" },
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"term_stars" : {
"terms" : { "field" : "stars" },
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"term_stars" : {
"terms" : {
"field" : "stars",
"order" : { "_term" : "desc" }
},
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"term_stars" : {
"terms" : {
"field" : "stars",
"order" : { "avg_price" : "asc" }
},
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"range_room" : {
"range" : {
"field" : "rooms",
"ranges" : [{"to":500}, {"from":500, "to":1000}, {"from":1000}]
},
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
}'
keyed
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"range_room" : {
"range" : {
"field" : "rooms",
"keyed" : true,
"ranges" : [{"to":500}, {"from":500, "to":1000}, {"from":1000}]
},
"aggs" : {
"avg_price" : {
"avg" : { "field" : "price" }
}
}
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"date_r_checkin" : {
"date_range" : {
"field" : "checkin",
"format" : "yyyy-MM-dd",
"ranges" : [{"to": "now-4M"}, {"from": "now-4M"}]
}
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"date_r_checkin" : {
"date_range" : {
"field" : "checkin",
"format" : "yyyy-MM-dd hh:mm:ss",
"ranges" : [{"to": "2014-03-05 12:30:45"}, {"from": "2014-03-05 12:30:45"}]
}
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"histo_rooms" : {
"histogram" : {
"field" : "rooms",
"interval" : 500
}
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"histo_rooms" : {
"histogram" : {
"field" : "rooms",
"interval" : 300,
"min_doc_count" : 0
}
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"aggs" : {
"geo_location" : {
"geo_distance" : {
"field" : "location",
"origin" : "37.52, 126.98",
"distance_type" : "plane",
"unit" : "km",
"ranges" : [{"to":3},{"from":3, "to":6},{"from":6, "to":9},{"from":9}]
}
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"term" : {
"title" : "prince"
}
}
}
'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"bool" : {
"filter" : {
"term" : {
"title" : "prince"
}
}
}
}
}
'
ํํ์ ๋ถ์
์๋ฌธ์๋ก ๊ฒ์
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"term" : {
"title" : "prince"
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"terms" : {
"title" : ["prince", "king"]
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"match" : {
"title" : "The And"
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"match" : {
"title" : {
"query" : "The And",
"operator" : "and"
}
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"match" : {
"title" : {
"query" : "prince king",
"analyzer" : "whitespace"
}
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"match" : {
"title" : {
"query" : "and the",
"type" : "phrase"
}
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"multi_match" : {
"fields" : [ "title", "plot" ],
"query" : "prince king"
}
}
}'
must
, must_not
, should
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"bool" : {
"must" : {
"term" : { "title" : "the" }
},
"must_not" : {
"term" : { "plot" : "prince" }
},
"should" : [
{"term" : { "title" : "time" } },
{"term" : { "title" : "world" } }
]
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"query_string" : {
"query" : "title:prince"
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"query_string" : {
"query" : "prince king",
"default_field" : "plot",
"default_operator" : "and"
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"prefix" : {
"title" : "prin"
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"range" : {
"pages" : { "gte" : 50, "lt" : 150 }
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"range" : {
"written" : {
"gte" : "1600-01-01",
"lt" : "1699-12-31"
}
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"match_all" : {}
}
}'
tree
๋ก ๊ฒ์์ three
ํฌํจcurl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"fuzzy" : {
"title" : "tree"
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"query" : {
"geo_bounding_box" : {
"location" : {
"top_left" : { "lat" : 38.00, "lon" : 126.00 },
"bottom_right" : { "lat" : 37.00, "lon" : 127.00 }
}
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"query" : {
"geo_distance" : {
"distance" : "5km",
"location" : { "lat" : 37.52, "lon" : 126.98 }
}
}
}'
curl 'localhost:9200/hotels/_search?pretty' -d '
{
"query" : {
"geo_polygon" : {
"location" : {
"points" : [
{ "lat" : 38.00, "lon" : 127.00 },
{ "lat" : 37.00, "lon" : 127.00 },
{ "lat" : 38.00, "lon" : 128.00 }
]
}
}
}
}'
_mapping
api ์ฌ์ฉcurl 'localhost:9200/books/_mapping?pretty'
curl -XPUT 'http://localhost:9200/books/_mapping/book' -d '
{
"book" : {
"properties" : {
"read" : { "type" : "boolean"}
}
}
}'
๋ํ๋จผํธ ๋ฐ์ดํฐ์ ์คํค๋ง ๊ตฌ์กฐ๋ฅผ ์ ์
_source
curl -XDELETE 'http://localhost:9200/books'
curl -XPUT 'http://localhost:9200/books' -d '
{
"mappings" : {
"book" : {
"_source" : { "enabled" : false }
}
}
}'
curl -XPOST localhost:9200/_bulk --data-binary @5_1_books.json
curl 'http://localhost:9200/books/_search?q=prince&pretty'
curl -XPUT 'http://localhost:9200/books' -d '
{
"mappings" : {
"book" : {
"_source" : {
"includes" : ["title", "author", "category"]
}
}
}
}'
curl -XPUT 'http://localhost:9200/books' -d '
{
"mappings" : {
"book" : {
"_source" : {
"excludes" : ["p*"]
}
}
}
}'
_all
curl -XPUT 'http://localhost:9200/books' -d '
{
"mappings" : {
"book" : {
"_all" : { "enabled" : true },
"properties" : {
"title" : {
"include_in_all" : true,
"type" : "string"
},
"plot" : {
"include_in_all" : false,
"type" : "string"
}
}
}
}
}'
์ด๋ฆ | ์ค๋ช | ๊ธฐ๋ณธ๊ฐ |
---|---|---|
store | ํ๋๊ฐ ์ ์ฅ ์ฌ๋ถ | false |
index | ๋ถ์๊ธฐ ์ ์ฉ ์ฌ๋ถ analyzed, not_analyzed, no | . |
boost | ํ๋ ๊ฐ์ค์น | 1.0 |
null_value | ํ๋ ์๋ ๊ฒฝ์ฐ ๊ธฐ๋ณธ๊ฐ ์ง์ | . |
analyzer | ๋ถ์๊ธฐ ์ง์ | . |
index_analyzer | ๋ฐ์ดํฐ ์์ธ์ ์ฌ์ฉ๋ ๋ถ์๊ธฐ ์ง์ | . |
search_analyzer | ๋ฌธ์์ด ๊ฒ์์ ์ฌ์ฉ๋ ๋ถ์๊ธฐ ์ง์ | . |
include_in_all | _all ๋งคํ ํ๋ ์ ์ฉ๋ ๊ฒฝ์ฐ ์์ธ ์ฌ๋ถ ์ง์ | . |
ignore_above | ์ง์ ๊ฐ๋ณด๋ค ํฐ ํฌ๊ธฐ์ ๋ฌธ์์ด ์์ธ ์ ์ธ | . |
curl 'localhost:9200/books/_search?q=prince&pretty'
curl 'localhost:9200/books/_search?q=category:science&pretty'
curl 'localhost:9200/books/_search?q=category:Science%20Fiction&pretty'
์ซ์
curl -XPUT 'localhost:9200/test_nums' -d '
{
"mappings" : {
"test_num" : {
"properties" : {
"num_val" : { "type" : "integer", "ignore_malformed" : true }
}
}
}
}'
curl -XPUT 'localhost:9200/test_nums/test_num/1' -d '
{
"num_val": "hello"
}'
curl 'localhost:9200/test_nums/test_num/1'
curl 'localhost:9200/test_nums/_search?pretty' -d '
{
"aggs" : {
"num_stat" : {
"stats" : { "field" : "num_val" }
}
}
}'
๋ ์ง
ignore_malformed
, format
์ต์
๋ถ๋ฆฐ
true
, false
๋ฐ์ด๋๋ฆฌ
store
, compress
, compress_threshold
๊ฐ์ฒด
์ค์ฒฉ
user.name
์ขํ
curl -XPUT localhost:9200/test_geos/ -d '
{
"mappings" : {
"test_geo" : {
"properties" : {
"name" : { "type" : "string" },
"location" : { "type" : "geo_point" }
}
}
}
}'
curl -XPUT 'localhost:9200/test_geos/test_geo/1' -d '
{
"name" : "Conrad Seoul",
"location" : "37.525308, 126.926644"
}'
curl 'http://localhost:9200/test_geos/_search?pretty' -d '
{
"query" : {
"geo_bounding_box" : {
"location" : {
"top_left": { "lat" : 37.53, "lon" : 126.92 },
"bottom_right" : {"lat" : 37.52, "lon" : 126.93 }
}
}
}
}'
curl -XPUT localhost:9200/test_geos/ -d '
{
"mappings" : {
"test_geo" : {
"properties" : {
"location" : {
"type" : "geo_shape",
"precision" : 10
}
}
}
}
}'
curl -XPUT 'localhost:9200/books' -d '
{
"mappings" : {
"book" : {
"properties" : {
"title" : {
"type" : "string", "index" : "analyzed",
"fields" : {
"raw" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"query" : {
"term" : { "title.raw" : "The Prince and the Pauper" }
}
}'
curl -XPUT 'localhost:9200/books' -d '
{
"mappings" : {
"book" : {
"properties" : {
"title" : {
"type" : "string", "index" : "analyzed",
"fields" : {
"tokens" : {
"type" : "token_count",
"store" : true,
"analyzer" : "standard"
}
}
}
}
}
}
}'
curl 'localhost:9200/books/_search?pretty' -d '
{
"fields" : [ "title", "title.tokens" ],
"query" : {
"term" : { "title" : "the" }
}
}'
curl -XPUT 'localhost:9200/books' -d '
{
"mappings" : {
"book" : {
"properties" : {
"title" : { "type" : "string", "copy_to" : "pk_data" },
"author" : { "type" : "string", "copy_to" : "pk_data" },
"pk_data" : { "type" : "string", "store" : true }
}
}
}
}'
curl -XPUT 'localhost:9200/books' -d '
{
"mappings" : {
"book" : {
"properties" : {
"title" : { "type" : "string", "copy_to" : ["title_1", "title_2"] },
"title_1" : { "type" : "string", "store" : true },
"title_2" : { "type" : "string", "store" : true }
}
}
}
}'
curl -XPOST 'localhost:9200/_analyze?tokenizer=whitespace&pretty' -d 'Around the World in Eighty Days'
curl -XPOST 'localhost:9200/_analyze?tokenizer=whitespace&filters=lowercase&pretty' -d 'Around the World in Eighty Days'
curl -XPOST 'localhost:9200/_analyze?tokenizer=whitespace&filters=lowercase,stop&pretty' -d 'Around the World in Eighty Days'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "whitespace",
"filter" : [ "lowercase", "stop" ]
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?pretty' -d 'Around the World in Eighty Days'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"standard" : {
"type" : "standard",
"stopwords" : ["in", "the", "world"],
"max_token_length" : 512
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=standard&pretty' -d 'Around the World in Eighty Days'
echo 'in
the
world' > config/stopword_list.txt
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"stop" : {
"type" : "stop",
"stopwords_path" : "stopword_list.txt"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=stop&pretty' -d 'Around the World in Eighty Days'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"pattern" : {
"type" : "pattern",
"lowercase" : false,
"pattern" : "[A-Z]"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=pattern&pretty' -d 'Around the World in Eighty Days'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"pattern" : {
"type" : "pattern",
"pattern" : "\\d"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=pattern&pretty' -d 'Around the World in 80 Days'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"language" : {
"type" : "english"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=language&pretty' -d '์ผ๊ตญ์ง(ไธๅๅฟ)'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"language" : {
"type" : "cjk"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=language&pretty' -d '์ผ๊ตญ์ง(ไธๅๅฟ)'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"snowball" : {
"type" : "snowball",
"pattern" : "english"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=snowball&pretty' -d 'Around the World in Eighty Days'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard"
}
}
}
}
}'
# ๋๋
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "my_tokenizer"
}
},
"tokenizer" : {
"my_tokenizer" : {
"type" : "standard"
}
}
}
}
}'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "my_ngram"
}
},
"tokenizer" : {
"my_ngram" : {
"type" : "nGram",
"min_gram" : "2",
"max_gram" : "3",
"token_chars" : [ "letter", "digit" ]
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Around the World in 80 Days'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "my_edgeNGram"
}
},
"tokenizer" : {
"my_edgeNGram" : {
"type" : "nGram",
"min_gram" : "2",
"max_gram" : "4",
"token_chars" : [ "letter", "digit" ]
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Around the World in 80 Days'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "my_hierarchy"
}
},
"tokenizer" : {
"my_hierarchy" : {
"type" : "path_hierarchy"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Program/Search/Elasticsearch'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "my_hierarchy"
}
},
"tokenizer" : {
"my_hierarchy" : {
"type" : "path_hierarchy",
"replacement" : "__html__quot;,
"skip" : 1
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Program/Search/Elasticsearch'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["standard"]
}
}
}
}
}'
# ๋๋
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["my_tokenfilter"]
}
},
"filter" : {
"my_tokenfilter" : {
"type" : "standard"
}
}
}
}
}'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["my_tokenfilter"]
}
},
"filter" : {
"my_tokenfilter" : {
"type" : "length",
"min" : 3, "max" : 5
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Around the World in Eighty Days'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["my_tokenfilter"]
}
},
"filter" : {
"my_tokenfilter" : {
"type" : "shingle",
"max_shingle_size" : 3,
"min_shingle_size" : 3
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Around the World in Eighty Days'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["stop", "my_tokenfilter"]
}
},
"filter" : {
"my_tokenfilter" : {
"type" : "shingle",
"max_shingle_size" : 3,
"min_shingle_size" : 3,
"output_unigrams" : false,
"token_separator" : "-",
"filler_token" : "*"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Around the World in Eighty Days'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "whitespace",
"filter" : ["my_tokenfilter"]
}
},
"filter" : {
"my_tokenfilter" : {
"type" : "word_delimiter"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d "Father's Wi-Fi SmartPhone, SD3000-12-Delux"
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "whitespace",
"filter" : ["my_keyword", "my_stemmer"]
}
},
"filter" : {
"my_keyword" : {
"type" : "keyword_marker",
"keywords" : ["swimming"]
},
"my_stemmer" : {
"type" : "stemmer",
"name" : "english"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Birds are flying, fishes are swimming, children are playing'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["keyword_repeat", "my_stemmer"]
}
},
"filter" : {
"my_stemmer" : {
"type" : "stemmer",
"name" : "english"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Birds are flying, fishes are swimming, children are playing'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["keyword_repeat", "my_stemmer", "my_unique"]
}
},
"filter" : {
"my_stemmer" : {
"type" : "stemmer",
"name" : "english"
},
"my_unique" : {
"type" : "unique"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Birds are flying, fishes are swimming, children are playing'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["snowball", "lowercase", "my_filter"]
}
},
"filter" : {
"my_filter" : {
"type" : "synonym",
"synonyms" : ["quick, fast", "jump, hop => hop"]
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'The Quick Rabbit Jumped'
echo 'quick, fast
jump, hop => hop' > config/synonym.txt
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["snowball", "lowercase", "my_filter"]
}
},
"filter" : {
"my_filter" : {
"type" : "synonym",
"synonyms_path" : "synonym.txt"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'The Quick Rabbit Jumped'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["my_filter"]
}
},
"filter" : {
"my_filter" : {
"type" : "dictionary_decompounder",
"word_list" : ["base", "ball"]
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'I play baseball and basketball'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["reverse"]
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Around the World in Eighty Days'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["my_filter"]
}
},
"filter" : {
"my_filter" : {
"type" : "truncate",
"length" : 4
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Around the World in Eighty Days'
open http://extensions.openoffice.org/en/project/us-english-spell-checking-dictionary
curl -O http://tenet.dl.sourceforge.net/project/aoo-extensions/1470/1/en_us.oxt
curl -O http://tenet.dl.sourceforge.net/project/aoo-extensions/5968/0/korean_spell-checker-0.5.6_ooo.oxt
unzip en_us.oxt
unzip korean_spell-checker-0.5.6_ooo.oxt
cd $ELASTICSEARCH_HOME
mkdir -p ../config/hunspell/en_US
cp en_US.* ../config/hunspell/en_US
mkdir -p ../config/hunspell/ko_KR
cp ko_KR.* ../config/hunspell/ko_KR
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["my_filter"]
}
},
"filter" : {
"my_filter" : {
"type" : "hunspell",
"locale" : "ko_KR"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d '๋ํด๋ฌผ๊ณผ ๋ฐฑ๋์ฐ์ด ๋ง๋ฅด๊ณ ๋ณ๋๋ก'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["my_filter"]
}
},
"filter" : {
"my_filter" : {
"type" : "cjk_bigram"
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d '์ผ๊ตญ์ง(ไธๅๅฟ)'
curl -XPUT 'localhost:9200/books' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_analyzer" : {
"tokenizer" : "standard",
"filter" : ["my_filter"]
}
},
"filter" : {
"my_filter" : {
"type" : "keep",
"keep_words" : ["the","Eighty","Days"]
}
}
}
}
}'
curl -XPOST 'localhost:9200/books/_analyze?analyzer=my_analyzer&pretty' -d 'Around the World in Eighty Days'
์์ ํ๋ข
install
url
# elasticsearch 5.1.1
./bin/elasticsearch-plugin install https://oss.sonatype.org/service/local/repositories/releases/content/org/bitbucket/eunjeon/elasticsearch-analysis-seunjeon/5.1.1.1/elasticsearch-analysis-seunjeon-5.1.1.1.zip
wget https://oss.sonatype.org/service/local/repositories/releases/content/org/bitbucket/eunjeon/elasticsearch-analysis-seunjeon/5.1.1.1/elasticsearch-analysis-seunjeon-5.1.1.1.zip
./bin/elasticsearch-plugin install file:///home/ec2-user/local/elasticsearch/elasticsearch-analysis-seunjeon-5.1.1.1.zip
# elasticsearch 2.4.1 ์ดํ
./bin/elasticsearch-plugin install org.bitbucket.eunjeon/elasticsearch-analysis-seunjeon/2.4.0.1
#!/usr/bin/env bash
ES='http://localhost:9200'
ESIDX='seunjeon-idx'
curl -XDELETE "${ES}/${ESIDX}?pretty"
sleep 1
curl -XPUT "${ES}/${ESIDX}/?pretty" -d '{
"settings" : {
"index":{
"analysis":{
"analyzer":{
"korean":{
"type":"custom",
"tokenizer":"seunjeon_default_tokenizer"
}
},
"tokenizer": {
"seunjeon_default_tokenizer": {
"type": "seunjeon_tokenizer",
"index_eojeol": false,
"user_words": ["๋๋ผ+๋น ๋น ,-100", "c\\+\\+", "์ด๊ทธ๋ก", "๋ฒ์นด์ถฉ", "abc๋งํธ"]
}
}
}
}
}
}'
sleep 1
echo "# ์ผ์ฑ/N ์ ์/N"
curl -XGET "${ES}/${ESIDX}/_analyze?analyzer=korean&pretty" -d '์ผ์ฑ์ ์'
echo "# ๋น ๋ฅด/V ์ง/V"
curl -XGET "${ES}/${ESIDX}/_analyze?analyzer=korean&pretty" -d '๋นจ๋ผ์ง'
echo "# ์ฌํ/V"
curl -XGET "${ES}/${ESIDX}/_analyze?analyzer=korean&pretty" -d '์ฌํ'
echo "# ์๋กญ/V ์ฌ์ /N ์์ฑ/N"
curl -XGET "${ES}/${ESIDX}/_analyze?analyzer=korean&pretty" -d '์๋ก์ด์ฌ์ ์์ฑ'
echo "# ๋๋ผ/N ๋น ๋น /N c++/N"
curl -XGET "${ES}/${ESIDX}/_analyze?analyzer=korean&pretty" -d '๋๋ผ๋น ๋น c++'
curl -XPOST 'localhost:9200/${ES}/_analyze?analyzer=korean&pretty' -d '๋ํด๋ฌผ๊ณผ ๋ฐฑ๋์ฐ์ด ๋ง๋ฅด๊ณ ๋ณ๋๋ก'
_delete-by-query
curl -XDELETE 'http://localhost:9200/twitter/tweet/_delete_by_query?q=user:kimchy'
#or
curl -XPOST 'http://localhost:9200/twitter/tweet/_delete_by__query' -d '
{
"query" : {
"term" : {
"user" : "kimchy"
}
}
}'
head plugin ์ค์น
bin/plugin install mobz/elasticsearch-head
cluster.name : my-application
in config/elasticsearch.yml
bin/elasticsearch
๋ค๋ฅธ ํฐ๋ฏธ๋๋ก 3๋ฒ ์คํ
http://localhost:9200/_plugin/head/
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
bin/plugin install file:/path/to/master.zip
์์ํ์ธ์! ์๋ผ์คํฑ์์น by ๊น์ข ๋ฏผ
Elasticsearch์์ ์๋ฆฌ๋ ํ๊ธ ๋ถ์๊ธฐ ์ฌ์ฉํ๊ธฐ
์์ ํ๋ข+elasticsearch
์๋ผ์คํฑ์์น ๊ธฐ์ด ์ฌ์ฉ๋ฒ by ๋ฐ์ฐ์ค