'elasticsearch'에 해당되는 글 420건

  1. 2013.01.15 elasticsearch + 한국어 형태소 분석기 색인 시 운영 경험 공유.
  2. 2013.01.14 Elasticsearch + 한국어형태소분석기 + JDK 호환 문제. 2
  3. 2013.01.09 elasticsearch query uri 예제들.
  4. 2013.01.03 elasticsearch plugin 설치하기
  5. 2013.01.03 elasticsearch routing 적용하기 1
  6. 2012.12.24 elasticsearch synonym 적용시 주의 사항.
  7. 2012.12.18 Elasticsearch 동의어/유의어 사전 활용
  8. 2012.12.17 elasticsearch uri 참고 링크
  9. 2012.11.22 Elasticsearch Cluster 구성하기 (shards, replicas)
  10. 2012.11.16 elasticsearch 설치 및 한글형태소분석기 적용 따라하기. 3

elasticsearch + 한국어 형태소 분석기 색인 시 운영 경험 공유.

Elastic/Elasticsearch 2013. 1. 15. 23:48

역쉬 쉬운게 없군요.. 
드뎌 elasticsearch 랑 kr analyzer 랑 문제를 해결했습니다.

제가 es 의 clustering 구성을 master node 를 두개로 구성했습니다.
그리고 색인 시 20개의 thread 를 생성해서 색인 데이터를 request 했구요.
물론 master node 한대를 target 으로 하고 request 했지요.

근데 es 내부에서 자동으로 master 끼리 분산 처리를 하더군요.

첨에는 소스 보기 귀찮아서 환경이랑 설정만 가지고 삽질을 했는데.. 도저희 해결이 안되서 소스를 직접 수정해서 디버깅을 하기 시작 했습니다.

짜잔.. ^^
해결책은 비교적 쉬운 곳에 있었습니다.

master node 를 하나만 사용하거나 thread safe 하도록 kr analyzer 소스를 조금 손봐주는 것입니다.

결론만 보면 정말 쉬운데요.. ㅋ 그 과정이 참 오래 걸렸내요.. 
그래도 뭐 빨리 찾았다고 생각 합니다.. ㅎㅎ

이상 es 운영 경험 공유를 맞칩니다. ^^


[해결방법1] <- 이건 근본해결책도 아니고 그냥 쓰레기 입니다. 그리고 data node 설정도 틀렸내요. 
- 서버 1 : node.master: true, node.data: true
- 서버 2 : 
node.master: false, node.data: true
아마도 
- 서버 1 : node.master: true, node.data: false
- 서버 2 : 
node.master: false, node.data: true
-> 다른 분이 테스트 해보시고 안된다고 그러시내요 ^^;


[해결방법2]

- SyllableUtil.java 에서 getSyllableFeature() 이 함수 내 FileUtil.readlines 를 threadsafe 하게 수정
- 저는 synchronized(lock) 으로 처리 했습니다.

:

Elasticsearch + 한국어형태소분석기 + JDK 호환 문제.

Elastic/Elasticsearch 2013. 1. 14. 11:02

아래 내용이 잘못 되어서 정정 합니다. ㅡ.ㅡ;;
kr_filter 부분에서 오류가 발생을 하는 것은 맞습니다.
다만, 해결책이 현재 클리어 하지 않은 상황이라 일단 적용한 스키마 코드랑 문제에 대한 차선책을 공유 합니다.
kr_filter 를 ngram 으로 변경했으나 이것도 최선은 아닙니다.

[문제가 된 스키마]

        "index" : {

            "analysis" : {

                "analyzer" : {

                    "kr_analyzer" : {

                        "type" : "custom",

                        "tokenizer" : "kr_tokenizer",

                        "filter" : ["trim", "kr_filter", "kr_synonym"]

                    },

                    "kr_analyzer" : {

                        "type" : "custom",

                        "tokenizer" : "kr_tokenizer",

                        "filter" : ["trim", "kr_filter", "kr_synonym"]

                    }

                },

                "filter" : {

                    "kr_synonym" : {

                        "type" : "synonym",

                        "synonyms_path" : "analysis/synonym.txt"

                    }

                }

            }

        }

[차선책]

        "index" : {

            "analysis" : {

                "analyzer" : {

                    "kr_analyzer" : {

                        "type" : "custom",

                        "tokenizer" : "kr_tokenizer",

                        "filter" : ["trim", "ngram", "kr_synonym"]

                    },

                    "kr_analyzer" : {

                        "type" : "custom",

                        "tokenizer" : "kr_tokenizer",

                        "filter" : ["trim", "ngram", "kr_synonym"]

                    }

                },

                "filter" : {

                    "kr_synonym" : {

                        "type" : "synonym",

                        "synonyms_path" : "analysis/synonym.txt"

                    },

                    "ngram" : {

                        "type" : "ngram",

                        "min_gram" : 2,

                        "max_gram" : 8

                    }

                }

            }

        }



운영을 하면서 발생한 이슈를 공유 합니다.

elasticsearch 0.19.12 + elasticsearch-analysis-korean-1.1.0 + jdk1.6.0 32
▷ 이 구성에서 JDK 버전으로 인해 분석기에서 오류가 발생 합니다.
▷ 오류 내용은 analysis 세팅 시 filter 부분에 trim 과 kr_filter 적용을 해야 합니다.
▷ 근데 이 두 filter 에서 색인 시 오류가 납니다.
▷ 해결책은 일단 개발 환경과 동일하게 JDK 버전을 낮춰서 해결을 했습니다.

사용 시 참고하세요.


그리고 elasticsearch-analysis-korean 이넘은 elasticsearch 0.19.9 로 빌드 되어 있어서 0.2x 버전이랑 함께 사용할 경우 오류가 납니다.
참고하세요.

:

elasticsearch query uri 예제들.

Elastic/Elasticsearch 2013. 1. 9. 12:02

기본적으로 /_plugin/head 에서 structured query 를 만들수 있지만 좀 더 다양한 옵션을 주고 싶을 경우 추가 구성을 해야 합니다.
elasticsearch.org 문서만 가지고 만들다 보면 처음 접하시는 분들은 어떻게 시작할지 막막할 수 있죠.
그래서 제가 테스트 했던 것들 올려 봅니다.


[기본쿼리]
http://localhost:9200/jjeong0/_search?q=msg:채팅&pretty=true
- msg 라는 field 에 대해서 검색 수행

http://localhost:9200/jjeong0/_search?q=msg:안녕 OR title:안녕하세요&sort=cre_ymdt:desc&from=0&size=10&pretty=true
- msg 와 title field 에 대해서 OR 검색을 수행


[JSON String Type]
[Paging+term 기반 쿼리]

http://localhost:9200/jjeong0/_search?source={"from":0,"size":10,"query":{"term":{"msg":"안녕하세요"}}}&pretty=true
- msg 라는 field 에 대해서 term 기반으로 검색 수행
- from 은 시작 offset 값이며, size 는 한 번에 fetch 해올 문서 크기

[Sorting + term 기반 쿼리]
http://localhost:9200/jjeong0/_search?source={"query":{"bool":{"must":[{"term":{"msg":"안녕"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[{"cre_ymdt":"asc"}],"facets":{}}&pretty=true
- msg 에 반드시 "안녕" 이라는 단어가 포함이 된 것만 검색
- cre_ymdt 값에 대한 ascending sorting
- http://www.elasticsearch.org/guide/reference/api/search/sort.html

[Range Search]
http://localhost:9200/jjeong0/_search?source={"query":{"range":{"recv_ymdt":{"from":"20120820163946", "to":"20120911160444"}}}}&pretty=true
- recv_ymdt 라는 값에 대해서 범위를 지정하고 검색
- http://www.elasticsearch.org/guide/reference/query-dsl/range-query.html

[Query String Search]
http://localhost:9200/jjeong0/_search?source={"query":{"bool":{"must":[{"query_string":{"default_field":"msg","query":"%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[{"cre_ymdt":"desc"}],"facets":{}}&pretty=true
- http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html

[Highlight Search]
http://localhost:9200/jjeong0/_search?source={"query":{"bool":{"must":[{"query_string":{"default_field":"msg","query":"안녕 하세요"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[{"cre_ymdt":"desc"}],"facets":{},"highlight":{"pre_tags":["<b>"],"post_tags":["</b>"],"fields":{"msg":{}}}}&pretty=true
- http://www.elasticsearch.org/guide/reference/api/search/highlighting.html

[Term+QueryString+Range+Highlight, Sort, Paging, Routing]
http://localhost:9200/jjeong0/_search?source={"from":0,"size":20,"query":{"bool":{"must":[{"term":{"user_uniq_id":"jjeong.tistory.com"}},{"query_string" : {"default_operator" : "OR","fields" : ["msg", "title"],"query" : "안먹어"}},{"range":{"rm_ymdt":{"from":"20121209000000","to":"20130110000000","include_lower":true,"include_upper":true}}}]}},"highlight":{"pre_tags":["<b>"],"post_tags":["</b>"],"fields":{"msg":{},"title":{}}},"sort":[{"cre_ymdt":{"order":"desc"}}]}&routing=jjeong.tistory.com&pretty=true
- http://www.elasticsearch.org/guide/reference/mapping/routing-field.html


:

elasticsearch plugin 설치하기

Elastic/Elasticsearch 2013. 1. 3. 14:49


Reference URL

  - 모든 plugin 은 설치 후 plugins 폴더를 복사해서 다른 서버로 옴겨서 설치 가능 함.
  - 사내에서는 사설 IP 사용 시 외부 네트워크 통신에 문제가 있는 경우 복사해서 구성 하면 됨.
bigdesk 설치
  - bin/plugin -install lukas-vlcek/bigdesk
  - http://localhost:9200/_plugin/bigdesk/
head 설치
  - bin/plugin -install Aconex/elasticsearch-head
- bin/plugin -install mobz/elasticsearch-head
  - http://localhost:9200/_plugin/head/
paramedic 설치
  - bin/plugin -install karmi/elasticsearch-paramedic
  - http://localhost:9200/_plugin/paramedic/index.html
kr_analyzer 설치
  - bin/plugin -install chanil1218/elasticsearch-analysis-korean/1.1.0
  - 형태소 분석기의 경우 elasticsearch 0.19.x 을 사용하기 때문에 0.20.x 에서는 오류가 발생 함

:

elasticsearch routing 적용하기

Elastic/Elasticsearch 2013. 1. 3. 14:47

Reference URL

Routing 이란?
  - 색인 시 특정 shard 로 색인을 하고, 검색 시 지정된 shard 로만 검색 할 수 있도록 지원
  - 색인 field 중 unique key 에 해당하는 값을 가지고 routing path 를 지정
  - 검색 시 지정한 path 를 query 에 주어 분산된 indices 를 모두 검색 하지 않고 지정된 indices 만 검색
  - routing field 는 store yes, index not_analyzed 로 설정 되어야 함
 
  - 기본 설정
        "routing" : {
            "required" : true,
            "path" : "test.user_uniq_id"
        }
Routing 설정하기
  - index 생성 시 routing 설정을 포함 시켜 생성 (replica 1, shards 50)
    "settings" : {
        "number_of_shards" : 50,
        "number_of_replicas" : 1,
        "index" : {
            "analysis" : {
                "analyzer" : {
                    "kr_analyzer" : {
                        "type" : "custom",
                        "tokenizer" : "kr_tokenizer",
                        "filter" : ["trim", "kr_filter", "kr_synonym"]
                    },
                    "kr_analyzer" : {
                        "type" : "custom",
                        "tokenizer" : "kr_tokenizer",
                        "filter" : ["trim", "kr_filter", "kr_synonym"]
                    }
                },
                "filter" : {
                    "kr_synonym" : {
                        "type" : "synonym",
                        "synonyms_path" : "analysis/synonym.txt"
                    }
                }
            }
        },
        "routing" : {
            "required" : true,
            "path" : "test.user_uniq_id"
        }
    },
    "mappings" : {
        "test" : {
            "properties" : {
                "docid" : { "type" : "string", "store" : "yes", "index" : "not_analyzed"},
                "title" : { "type" : "string", "store" : "yes", "index" : "analyzed", "term_vector" : "yes", "analyzer" : "kr_analyzer" },
                "user_uniq_id" : { "type" : "string", "store" : "yes", "index" : "not_analyzed" },
                "ymdt" : { "type" : "date", "format" : "yyyyMMddHHmmss", "store" : "yes", "index" : "not_analyzed" }
                }
            }
        }
    }
}'
 
  - document 색인 시 setRouting 설정을 해줘야 정상 동작 함
    IndexRequestBuilder requestBuilder = client.prepareIndex(indexName, indexType);
    requestBuilder.setId(docId);
    requestBuilder.setRouting(docMeta.getUserUniqId());
    requestBuilder.setSource(jsonBuilder);
routing search query uri
  - http://localhost:9200/index0/_search?source={"query":{"bool":{"must":[{"term":{"user_uniq_id":"honggildong@elastic.com"}}],"must_not":[],"should":[]}},"from":0,"size":50,"sort":[{"ymdt":"asc"}],"facets":{}}&routing=honggildong@elastic.com&pretty=true




:

elasticsearch synonym 적용시 주의 사항.

Elastic/Elasticsearch 2012. 12. 24. 11:07

synonym 관련 글은 아래 참고 하시구요.
제가 적용 하면서 실수했던 내용을 공유 합니다.

1. cluster 구성을 했을 경우 synonym.txt 파일을 모든 서버에 생성을 해야 합니다.
  : 당연한 이야기 인데 저는 클러스터 구성한걸 까맣게 잊고 서버 한대에만 적용해 놓고 왜 안되지 이러고 있었습니다. ㅡ.ㅡ;;

2. synonym.txt 파일 위치 지정
  : elasticsearch.org 에도 있는데 문서를 제대로 안읽어 보고 파일을 어디에 놓아야 하는거야 하고 삽질을 했습니다.
  : 기본 설치된 경로에서 config 폴더를 기준으로 상대경로로 인식 합니다. (analysis/synonym.txt)
  : 소스 코드를 보면 full path 로 넣으셔도 됩니다. (소스를 보는 것도 좋은 에러 해결 방법 입니다.)
  : Environment.java (org.elasticsearch.env 패키지 아래 있습니다.)


그리고 제가 적용한 방법은 solr 용으로 테스트 하였습니다.

:

Elasticsearch 동의어/유의어 사전 활용

Elastic/Elasticsearch 2012. 12. 18. 22:22

[title=Elasticsearch 동의어/유의어 설정]

- 색인 파일 생성 시 설정을 해줘야 함

- 기본 kr_analysis 가 적용되어 있어야 함

  - 없을 경우 한국어 처리가 안됨

- synonym.txt 파일을 적절한 위치에 생성

  - http://www.elasticsearch.org/guide/reference/index-modules/analysis/synonym-tokenfilter.html


[title=synonym.txt 샘플]

Solr synonyms


The following is a sample format of the file:


# blank lines and lines starting with pound are comments.


#Explicit mappings match any token sequence on the LHS of "=>"

#and replace with all alternatives on the RHS.  These types of mappings

#ignore the expand parameter in the schema.

#Examples:

i-pod, i pod => ipod,

sea biscuit, sea biscit => seabiscuit


#Equivalent synonyms may be separated with commas and give

#no explicit mapping.  In this case the mapping behavior will

#be taken from the expand parameter in the schema.  This allows

#the same synonym file to be used in different synonym handling strategies.

#Examples:

ipod, i-pod, i pod

foozball , foosball

universe , cosmos


# If expand==true, "ipod, i-pod, i pod" is equivalent to the explicit mapping:

ipod, i-pod, i pod => ipod, i-pod, i pod

# If expand==false, "ipod, i-pod, i pod" is equivalent to the explicit mapping:

ipod, i-pod, i pod => ipod


#multiple synonym mapping entries are merged.

foo => foo bar

foo => baz

#is equivalent to

foo => foo bar, baz


[색인파일 생성 샘플코드 - synonym 적용]

curl -XPUT 'http://localhost:9200/test' -d '{

    "settings" : {

        "number_of_shards" : 5,

        "number_of_replicas" : 1,

        "index" : {

            "analysis" : {

                "analyzer" : {

                    "kr_analyzer" : {

                        "type" : "custom",

                        "tokenizer" : "kr_tokenizer",

                        "filter" : ["trim", "kr_filter", "kr_synonym"]

                    },

                    "kr_analyzer" : {

                        "type" : "custom",

                        "tokenizer" : "kr_tokenizer",

                        "filter" : ["trim", "kr_filter", "kr_synonym"]

                    }

                },

                "filter" : {

                    "kr_synonym" : {

                        "type" : "synonym",

                        "synonyms_path" : "analysis/synonym.txt"

                    }

                }

            }

        }

    }'


[title=색인파일 생성 샘플코드]

curl -XPUT 'http://10.101.254.223:9200/test' -d '{

    "settings" : {

        "number_of_shards" : 5,

        "number_of_replicas" : 1

    },

    "index" : {

        "analysis" : {

            "analyzer" : {

                "synonym" : {

                    "tokenizer" : "kr_analyzer",

                    "filter" : ["synonym"]

                }

            },

            "filter" : {

                "synonym" : {

                    "type" : "synonym",

                    "synonyms_path" : "/home/계정/apps/elasticsearch/plugins/analysis-korean/analysis/synonym.txt"

                }

            }

        }

    },

    "mappings" : {

        "docs" : {

            "properties" : {

 ...................................(요기 부분은 다른 문서들 참고 하시면 됩니다.)

                    }

                }

            }

        }

    }

}'

:

elasticsearch uri 참고 링크

Elastic/Elasticsearch 2012. 12. 17. 10:00

색인 파일 저장위치 변경
http://www.elasticsearch.org/guide/reference/setup/configuration.html

검색 uri 형식 restful 형식
http://stackoverflow.com/questions/12195017/different-result-when-using-get-post-in-elastic-search

http://localhost:9200/_search&{"query":{"term":{"text":"john"}}}
http://localhost:9200/_search?source={"query":{"term":{"text":"john"}}}

date range search 형식
http://stackoverflow.com/questions/11351296/elastic-search-date-range-query
{
    "query" : {
        "range" : {
            "PublishTime" : {
                "from" : "20111201T000000",
                "to" : "20111203T235959"
            }
        }
    }
}

:

Elasticsearch Cluster 구성하기 (shards, replicas)

Elastic/Elasticsearch 2012. 11. 22. 17:34

많이 부족하지만 일단 스스로 정리하기 위해서.. 올립니다. ^^;

[Reference]

    http://www.elasticsearch.org

    http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html


[URI Command]

    http://10.101.254.223:9200/_status

    http://10.101.254.223:9200/_cluster/state?pretty=true

    http://10.101.254.223:9200/_cluster/nodes?pretty=true

    http://10.101.254.223:9200/_cluster/health?pretty=true


[색인파일 setting 확인]

    http://10.101.254.223:9200/depth1_1/_settings?pretty=true


[색인파일 mapping 확인]

    http://10.101.254.223:9200/depth1_1/_mapping?pretty=true


[색인파일의 URI Step 정의]

    /depth1/

        index 명 (각 서비스 단위의 색인명 or vertical service 명)

        예)

            /blog

            /cafe

    /depth1/depth2/

        index type 명

        예)

            /blog/user

            /blog/post

            /cafe/user

            /cafe/post

    /depth1/depth2/depth3

        색인된 document unique key (id)


[색인파일의 생성, shard, replica 설정]

    http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html


    - case 1

        curl -XPUT 'http://10.101.254.221:9200/depth1/'


    - case 2

        curl -XPUT 'http://10.101.254.221:9200/depth1_2/' -d '

        index :

            number_of_shards : 3

            number_of_replicas : 2

        '


    - case 3 : recommended

        curl -XPUT 'http://10.101.254.223:9200/depth1_1/' -d '{

            "settings" : {

                "index" : {

                    "number_of_shards" : 3,

                    "number_of_replicas" : 2

                }

            }

        }'


    - case 4

        curl -XPUT 'http://10.101.254.223:9200/depth1_1/' -d '{

            "settings" : {

                "number_of_shards" : 3,

                "number_of_replicas" : 2

            }

        }'


[색인파일 mapping 설정]

    http://www.elasticsearch.org/guide/reference/mapping/

    http://www.elasticsearch.org/guide/reference/mapping/core-types.html

    ※ 이 영역에서 색인 또는 검색 시 사용할 analyzer 나 tokenizer 를 지정 한다.

    ※ solr 의 경우 schema.xml 에서 정의 하는 설정을 여기서 수행 함.


    curl -XPUT 'http://10.101.254.223:9200/depth1_1/depth2_1/_mapping' -d '

    {

        "depth2_1" : {

            "properties" : {

                "FIELD명" : {"type" : "string", "store" : "yes"}

            }

        }

    }'


[데이터 색인]

    http://www.elasticsearch.org/guide/reference/api/index_.html


    curl -XPUT 'http://10.101.254.223:9200/blog/user/dilbert' -d '{ "name" : "Dilbert Brown" }'


    curl -XPUT 'http://10.101.254.223:9200/blog/post/1' -d '

    {

        "user": "dilbert",

        "postDate": "2011-12-15",

        "body": "Search is hard. Search should be easy." ,

        "title": "On search"

    }'


    curl -XPUT 'http://10.101.254.223:9200/blog/post/2' -d '

    {

        "user": "dilbert",

        "postDate": "2011-12-12",

        "body": "Distribution is hard. Distribution should be easy." ,

        "title": "On distributed search"

    }'


    curl -XPUT 'http://10.101.254.223:9200/blog/post/3' -d '

    {

        "user": "dilbert",

        "postDate": "2011-12-10",

        "body": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat" ,

        "title": "Lorem ipsum"

    }'


    curl -XPUT 'http://10.101.254.223:9200/blog/post/4' -d '

    {

        "user": "dilbert",

        "postDate": "2011-12-11",

        "body": "한글 형태소 분석기 테스트와 shard 그리고 replica 테스트" ,

        "title": "elastic search 분산설정"

    }'


    curl -XGET 'http://10.101.254.223:9200/blog/user/dilbert?pretty=true'

    curl -XGET 'http://10.101.254.221:9200/blog/post/1?pretty=true'

    curl -XGET 'http://10.101.254.223:9200/blog/post/2?pretty=true'

    curl -XGET 'http://10.101.254.221:9200/blog/post/3?pretty=true'


[검색테스트]

    http://www.elasticsearch.org/guide/reference/api/search/uri-request.html

    - user에 dilbert 가 포함되어 있는 것

    curl 'http://10.101.254.221:9200/blog/post/_search?q=user:dilbert&pretty=true'

    http://10.101.254.223:9200/blog/post/_search?q=user:dilbert&pretty=true


    - title 에 search 가 포함 안된 것

    curl 'http://10.101.254.223:9200/blog/post/_search?q=-title:search&pretty=true'

    http://10.101.254.223:9200/blog/post/_search?q=-title:search&pretty=true


    - title 에 search 는 있고 distributed 는 없는 것

    curl 'http://10.101.254.223:9200/blog/post/_search?q=+title:search%20-title:distributed&pretty=true&fields=title'

    http://10.101.254.223:9200/blog/post/_search?q=+title:search%20-title:distributed&pretty=true&fields=title


    - range 검색

    curl -XGET 'http://10.101.254.223:9200/blog/_search?pretty=true' -d '

    {

        "query" : {

            "range" : {

                "postDate" : { "from" : "2011-12-10", "to" : "2011-12-12" }

            }

        }

    }'


    - blog 라는 색인 파일 전체 검색

        http://10.101.254.223:9200/blog/_search?q=user:dilbert&pretty=true

        http://10.101.254.223:9200/blog/_search?q=name:dilbert&pretty=true


    - routing 검색 (정확한 의미 파악이 어려움)

        http://10.101.254.223:9200/blog/_search?routing=dilbert?prettry=true


[Clustering 설정 정보]

    ※ 서버1

        cluster.name: cluster_es1

        node.name: node_es1

        node.master: true

        node.data: true

        node.rack: rack_es1

        index.number_of_shards: 3

        index.number_of_replicas: 2

        network.host: 10.101.254.223

        transport.tcp.port: 9300

        http.port: 9200

        gateway.type: local

        gateway.recover_after_nodes: 1

        gateway.recover_after_time: 5m

        gateway.expected_nodes: 2

        cluster.routing.allocation.node_initial_primaries_recoveries: 4

        cluster.routing.allocation.node_concurrent_recoveries: 2

        indices.recovery.max_size_per_sec: 0

        indices.recovery.concurrent_streams: 5

        discovery.zen.minimum_master_nodes: 1

        discovery.zen.ping.timeout: 3s

        discovery.zen.ping.unicast.hosts: ["10.101.254.223:9300", "10.101.254.221:9300"]

        cluster.routing.allocation.allow_rebalance: "indices_all_active"

        indices.recovery.concurrent_streams: 3

        action.auto_create_index: true

        index.mapper.dynamic: true


    ※ 서버2

        cluster.name: cluster_es1

        node.name: node_es2

        node.master: true

        node.data: true

        node.rack: rack_es1

        index.number_of_shards: 3

        index.number_of_replicas: 2

        network.host: 10.101.254.221

        transport.tcp.port: 9300

        http.port: 9200

        gateway.type: local

        gateway.recover_after_nodes: 1

        gateway.recover_after_time: 5m

        gateway.expected_nodes: 2

        cluster.routing.allocation.node_initial_primaries_recoveries: 4

        cluster.routing.allocation.node_concurrent_recoveries: 2

        indices.recovery.max_size_per_sec: 0

        indices.recovery.concurrent_streams: 5

        discovery.zen.minimum_master_nodes: 1

        discovery.zen.ping.timeout: 3s

        discovery.zen.ping.unicast.hosts: ["10.101.254.223:9300", "10.101.254.221:9300"]

        cluster.routing.allocation.allow_rebalance: "indices_all_active"

        indices.recovery.concurrent_streams: 3

        action.auto_create_index: true

        index.mapper.dynamic: true


[설정파일의미]

    ※ 클러스터링할 그룹명 (묶고자 하는 서버들에 elasticsearch.yml 파일에서 이름을 동일하게 주면 클러스터링 됨)

        cluster.name: group1


    ※ 검색 및 색인 서버로 사용하고자 할 경우 설정

        node.master: true

        node.data : true


    ※ 검색 전용 서버로 사용하고자 할 경우 설정 (검색 로드발라서)

        node.master: false

        node.data : false


    ※ 색인 전용 서버로 사용하고자 할 경우 설정

        node.master: false

        node.data : true


    ※ 이건 용도를 잘 모르겠음

        node.master: true

        node.data : false


    ※ 색인 파일(데이터) 사이즈가 작을 경우 수치를 작게 (1), 사이즈가 클 경우 수치를 크게 (기본 5)

    ※ 하나의 색인 파일을 몇 개로 나눠서 저장할 것인지 정의

        index.number_of_shards: 5


    ※ 색인 파일에 대한 복사본 생성 수치 (기본 1)

        index.number_of_replicas: 1


    ※ 설정 후 서버간 클러스터링 되는 과정을 파악하기 어려움

        두 대의 서버에 cluster.name 을 같게 해서 실행 시켜면 자동으로 clustering 됨


    ※ 서버 한대에서 여러개의 elasticsearch instacne 실행 방법

        ./elasticsearch -p pidfile1 -Des.config=elasticsearch/config/elasticsearch1.yml

        ./elasticsearch -p pidfile2 -Des.config=elasticsearch/config/elasticsearch2.yml


        ※ 기타 옵션

        -Xmx1g -Xms1g -Des.max-open-files=true


    ※ node 의 의미

        elasticsearch 에서 node == index 에 의미를 가짐

:

elasticsearch 설치 및 한글형태소분석기 적용 따라하기.

Elastic/Elasticsearch 2012. 11. 16. 13:03

[ElasticSearch 설치하기]

    ※ 참고 URL

    http://www.elasticsearch.org/tutorials/2010/07/01/setting-up-elasticsearch.html

    http://mimul.com/pebble/default/2012/02/23/1329988075236.html

    https://github.com/chanil1218/elasticsearch-analysis-korean

    http://apmlinux.egloos.com/2976457


    ※ 다운로드

    wget --no-check-certificate https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.11.tar.gz


    ※ 압축해제

    tar -xvzf elasticsearch-0.19.11.tar.gz


    ※ 링크생성

    ln -s elasticsearch-0.19.11 elasticsearch


    ※ 설정

    cd elasticsearch/config

    vi elasticsearch.yml

        # cluster.name: elasticsearch

        cluster.name: MyCluster


        # network.host: 192.168.0.1

        network.host: 10.101.254.223


        # http.port: 9200

        http.port: 9200


    ※ 실행

    bin/elasticsearch -f

    OR

    bin/elasticsearch -p pidfile


    ※ 기능확인

    curl -X GET http://10.101.254.223:9200/


    ※ 관리툴설치

    bin/plugin -install mobz/elasticsearch-head

    http://10.101.254.223:9200/_plugin/head/


    ※ 한글형태소분석기설치

    bin/plugin -install chanil1218/elasticsearch-analysis-korean/1.1.0


    ※ 한글형태소분석기 설정 (elasticsearch 재실행 후 설정)

    curl -XPUT http://10.101.254.223:9200/test  -d '{

    "settings" : {

        "index": {

            "analysis": {

                "analyzer": {

                    "kr_analyzer": {

                        "type": "custom"

                            , "tokenizer": "kr_tokenizer"

                            ,"filter" : ["trim","kr_filter"]

                    }

                    , "kr_analyzer": {

                        "type": "custom"

                            , "tokenizer": "kr_tokenizer"

                            ,"filter" : ["trim","kr_filter"]

                    }

                }

            }

        }

    }

    }'


    ※ 한글형태소분석기 테스트

    curl -XGET 'http://10.101.254.223:9200/test/_analyze?analyzer=kr_analyzer&pretty=true' -d '전주비빔밥'

        ※ 한글형태소분석결과

        {

          "tokens" : [ {

            "token" : "전주비빔밥",

            "start_offset" : 0,

            "end_offset" : 5,

            "type" : "word",

            "position" : 1

          }, {

            "token" : "전주",

            "start_offset" : 0,

            "end_offset" : 2,

            "type" : "word",

            "position" : 2

          }, {

            "token" : "비빔밥",

            "start_offset" : 2,

            "end_offset" : 5,

            "type" : "word",

            "position" : 3

          } ]

        }

: