'elasticsearch'에 해당되는 글 420건

  1. 2014.12.04 [Elasticsearch] simple dynamic template 테스트
  2. 2014.11.19 [Elasticsearch] embedded elasticsearrch server 테스트.
  3. 2014.11.19 [Elasticsearch] ElasticsearchIntegrationTest pom.xml 구성하기.
  4. 2014.11.19 [Elasticsearch] ElasticsearchIntegrationTest 삽질 공유.
  5. 2014.11.18 [Elasticsearch] minimum_master 설정 참고.
  6. 2014.11.13 [Kibana] es 공식 가이드 문서 링크.
  7. 2014.11.13 [Elasticsearch] JDBC River 추가 REST API 팁!!
  8. 2014.11.13 [Elasticsearch] scale up limitation. 2
  9. 2014.11.12 JDBC River의 strategy 란?
  10. 2014.10.30 [ElasticSearch] _score 계산 시 IDF 연산은 어떻게 이루어 지나요?

[Elasticsearch] simple dynamic template 테스트

Elastic/Elasticsearch 2014. 12. 4. 18:01


[Setting 설정]

{

"settings" : {

"number_of_shards" : 3,

"number_of_replicas" : 0

}

}


- 생성

curl -XPUT 'http://localhost:9200/dynamic_template -d @setting.json


[Mapping 설정]

{

"_source" : {

"enabled" : "true"

},

"_all" : {

"enabled" : "false"

},

        "dynamic_templates": [

        {

            "string_match": {

                "mapping": {

                    "index": "not_analyzed",

                    "type": "string"

                },

                "match_mapping_type": "string",

                "match": "*"

            }

        }

      ],

     "properties" : {}

}


- 생성

curl -XPUT http://localhost:9200/dynamic_template/test1/_mapping -d @mapping.json

curl -XPUT http://localhost:9200/dynamic_template/test2/_mapping -d @mapping.json


[Add document]

curl -XPOST http://127.0.0.1:9200/dynamic_template/test1 -d '{"docid" : "1"}'

curl -XPOST http://127.0.0.1:9200/dynamic_template/test2 -d '{"docid" : 1}'



이후 test1과 test2에 설정된 docid 필드에 대한 type을 확인을 해보면 아래와 같이 나오게 된다.


{

   "dynamic_template": {

      "mappings": {

         "test2": {

            "dynamic_templates": [

               {

                  "string_match": {

                     "mapping": {

                        "index": "not_analyzed",

                        "type": "string"

                     },

                     "match": "*",

                     "match_mapping_type": "string"

                  }

               }

            ],

            "_all": {

               "enabled": false

            },

            "properties": {

               "docid": {

                  "type": "long"

               }

            }

         },

         "test1": {

            "dynamic_templates": [

               {

                  "string_match": {

                     "mapping": {

                        "index": "not_analyzed",

                        "type": "string"

                     },

                     "match": "*",

                     "match_mapping_type": "string"

                  }

               }

            ],

            "_all": {

               "enabled": false

            },

            "properties": {

               "docid": {

                  "index": "not_analyzed",

                  "type": "string"

               }

            }

         }

      }

   }

}



:

[Elasticsearch] embedded elasticsearrch server 테스트.

Elastic/Elasticsearch 2014. 11. 19. 16:59

내가 만드는 application 에 es 를 포함시켜 놓고 사용하고 싶을 때 사용하시면 됩니다.

이걸 어디에 사용하느냐는 알아서들 하시구요. ^^


기본 로직만 담아서 main 함수에 넣었으니 입맛에 맞게 수정 하시면 되겠내요.


[Embedded Elasticsearch Server]

public class EmbeddedElasticsearchServer {


    public static void main(String[] args) {

        ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();

        settings.put("node.name", "embedded-local-node");

        settings.put("path.data", "data/index");


        Node node = NodeBuilder.nodeBuilder()

            .settings(settings)

            .clusterName("embedded-local-cluster")

            .data(true)

            .local(true)

            .node();


        Client client = node.client();


        CreateIndexRequest request = Requests.createIndexRequest("embedded-index").settings(settings);

        CreateIndexResponse response = client.admin().indices().create(request).actionGet();


        client.close();


        // node.close() 가 호출 되면 embedded elasticsearch daemon 은 stop 된다.

        node.close();

    }

}


보시면 기본 flow 는 이렇습니다.


1. elasticsearch.yml 을 대신 할 settings를 설정 합니다.

2. 1번 settings 정보를 갖는 node 를 생성 합니다.

----> 여기까지만 하면 es daemon 이 실행 됩니다.

3. embedded es server 로 접속할 client를 생성 합니다.

4. client를 이용해 index를 생성 합니다.

5. client 접속을 끊습니다.

----> client 가 close 되었지 daemon 은 그대로 listen 하고 있습니다.

6. embedded es server 를 종료 합니다.

----> node.close() 해야만 데몬이 종료 합니다.


여기까지가 기본 이구요.

활용은 각자 알아서 하시는 걸로 ^^

:

[Elasticsearch] ElasticsearchIntegrationTest pom.xml 구성하기.

Elastic/Elasticsearch 2014. 11. 19. 16:15

이게 그냥 es source 받아서 돌리면 잘 됩니다.

ElasticsearchIntegrationTest 를 상속 받아서 테스트 하기 위해서는 테스트 프로젝트의 pom.xml 에 dependency 설정을 잘해야 합니다.


es쪽 문서에는 나와 있지 않습니다.

뭐 오류 수정해서 코드에 반영하면 되니까 문서를 고칠 필요는 없을 수도 있겠내요.


http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/using-elasticsearch-test-classes.html


아래는 제가 테스트한 pom.xml 입니다.


[pom.xml]


:

[Elasticsearch] ElasticsearchIntegrationTest 삽질 공유.

Elastic/Elasticsearch 2014. 11. 19. 13:56

이게 참 그냥 되야 하는 건데 eclipse 설정 환경에 따라 안될 수도 있으니 저 처럼 삽질 하시는 분들이 없도록 공유해 보겠습니다.

여기서 가장 중요한건 에러 메시지에 대한 인지를 얼마나 잘해서 문제를 해결 할수 있도록 접근하느냐 인것 같습니다.


[Elasticsearch 1.4.0]

Step 1) test class 중 아무거나 하나 실행


아래 에러 메시지 출력

Assertions mismatch: -ea was not specified but -Dtests.asserts=true

[2014-11-19 13:05:15,135][ERROR][org.elasticsearch.test   ] FAILURE  : org.elasticsearch.action.OriginalIndicesTests

REPRODUCE WITH  : mvn clean test -Dtests.seed=F00EC17F5FF1D602 -Dtests.class=org.elasticsearch.action.OriginalIndicesTests -Dtests.prefix=tests -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Seoul -Dtests.processors=8

Throwable:

java.lang.Exception: Assertions mismatch: -ea was not specified but -Dtests.asserts=true

    __randomizedtesting.SeedInfo.seed([F00EC17F5FF1D602]:0)

    org.apache.lucene.util.TestRuleAssertionsRequired$1.evaluate(TestRuleAssertionsRequired.java:48)

    org.apache.lucene.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:48)

    org.apache.lucene.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:65)

    org.apache.lucene.util.TestRuleIgnoreTestSuites$1.evaluate(TestRuleIgnoreTestSuites.java:55)

    [...com.carrotsearch.randomizedtesting.*]

    java.lang.Thread.run(Thread.java:745)


여기서 핵심은 assertion mismatch 부분 입니다.

딱 봐도 거긴데요.

구글링을 어떻게 하느냐에 따라서 삽질이 될 수도 안될 수도 있습니다. ㅡㅡ;

(참고로 저는 ElasticsearchIntegrationTest error or issue or problem + assertions mismatch + randomizedtesing .,..)


Step 2) REPRODUCE WITH 를 가지고 console 에서 실행.

매우 잘 동작 합니다. ㅡ.ㅡ;;

그래서 멘붕..


Step 3) junit run configure 에 VM 옵션 추가 테스트

아래와 같이 추가 해 봄 

-Dtests.asserts=true

젠장 역시 안됨.


Step 4) 루씬 소스코드도 까보고 이것 저것 삽질 끝에 구글링을 재시도

아래는 재시도 질의

eclipse junit assert enable


Step 5) 두 가지 방법으로 test 성공

1. eclipse preference -> junit -> Add -ea checkbox enable.

2. 해당 test class -> run as -> run configure -> argementgs tab -> vm agrguments 에 -ea 옵션 추가.


이제 저 처럼 삽질 하지 마시고 편하게 es test 하세요.



:

[Elasticsearch] minimum_master 설정 참고.

Elastic/Elasticsearch 2014. 11. 18. 16:29

minimum_master 노드 설정은 예전에 최소 2 이상이라고 했었습니다.

하지만 이건 단순 예시이고 실제 node 구성에 맞춰서 설정 하는게 맞습니다.

기본 설정 가이드는 master node 로 지정된 크기의 quorum size 로 하시는게 좋습니다.


예시)

전체 노드 수 => 5대

node.master: true  => 2대

quorum size = 2/2 + 1 => 2대

즉, minimum_master: 2 가 되는 것입니다.


이와 같이 구성하게 되면 master node 가 하나 fail 났을때 장애로 이어지게 됩니다.

이유는 minimum_master 가 2가 안되기 때문입니다.


이 경우 node.master를 3개로 늘려 주시면 됩니다.

또는 minimum_master를 1개로 줄여 주셔되 되지만, 이 경우 failover 에 대한 대안이 없기 때문에 추천 하지 않습니다.


node.master 수와 minimum_master 간의 조합을 잘 하셔서 failover 구성을 하시기 바랍니다.

:

[Kibana] es 공식 가이드 문서 링크.

Elastic/Elasticsearch 2014. 11. 13. 15:37

http://www.elasticsearch.org/overview/kibana/installation/

http://www.elasticsearch.org/guide/en/kibana/current/index.html


※ chrome 에서 사용시 주의 사항.

- 기존에 이전 버전을 사용중이였다면 cache 및 temporary file 을 모두 삭제 하고 할 것.

- web server 로 tomcat과 같은 web application server를 사용할 경우 cache 된 파일 삭제 하고 할 것.

:

[Elasticsearch] JDBC River 추가 REST API 팁!!

Elastic/Elasticsearch 2014. 11. 13. 12:57

오픈소스의 좋은 점이기도 하지만 조금 불편한 점도 있죠.

사용방법이나 어디 레퍼런스가 없어서 소스코드를 확인해야만 하는 노가다!!


ㅎㅎ 뭐 그래도 재밌으면 그걸로 만족 ^^


JDBC River 테스트 중에 2014년 10월에 추가된 API 가 있어서 테스트 하던 중 아래 에러가 나와서 소스코드 확인 후 어떻게 사용해야 하는지 알게 되었내요.


[에러코드]

{"error":"NullPointerException[null]","status":500}


[추가된 REST API]

_state

_suspend

_abort

_resume

_run


[테스트 버전]

elasticsearch 1.3.4

elasticsearch jdbc river 1.3.4.4


[Request 방법]

$ curl -d "{\"rivername\":\"my_jdbc_river\"} -XPOST http://localhost:9200/_river/jdbc/{REST_API}

- 일단 _state 는 GET 입니다. POST 로 던지고 안된다고 하지 마세요.

- 문서에도 없는 내용입니다. rivername 이라는 parameter 를 구성해서 넘겨줘야 합니다.

- JSON 형태로 넘기셔야 됩니다.


기타 자세한 설명은 아래 링크 참고하세요.

Ref. https://github.com/jprante/elasticsearch-river-jdbc


:

[Elasticsearch] scale up limitation.

Elastic/Elasticsearch 2014. 11. 13. 11:28

elasticsearch에 대한 scale up 고려 시 참고 하세요.

장비 스펙이 너무 좋아도 리소스를 제대로 사용하지 못하면 의미가 없겠죠.


- Less than equal 32GB ram

- Less than equal 32 cores

:

JDBC River의 strategy 란?

Elastic/Elasticsearch 2014. 11. 12. 11:41

https://github.com/jprante/elasticsearch-river-jdbc


현재까지 제공되는 strategy 옵션은 두개 입니다.


1) simple

2) column


simple은 단순 fetch 와 indexing or delete 작업을 수행 하는 것 이라고,

column은 마지막에 수행한 정보를 기록해 두었다가 값을 비교하여 indexing or delete 작업을 수행 하는 것 입니다.


:

[ElasticSearch] _score 계산 시 IDF 연산은 어떻게 이루어 지나요?

Elastic/Elasticsearch 2014. 10. 30. 11:53

어제 저희 회사 행사에서 "오픈소스 검색엔진 구축 사례"로 발표를 했었는데요.

저에게 질문 주셨던 것중에 나름 재밌는 질문을 주셨던 내용이 있어서 공유 드립니다.


(아마도 질문 주신 분은 elasticsearch 를 사용해 보지 않으셨거나 경험 하신지 얼마 안되신 것 같다는 느낌 이였구요. lucene 은 많이 사용해보신 분 같다는 느낌 이였습니다. ㅎㅎ 제 느낌이니 틀릴수도 있구요.)


질문은 이랬던것 같습니다. 

- elasticsearch 에서  색인 시에, IDF 값을 Global 하게 쓰기 어려울 텐데 어떻게 사용되는 지에 대한 질문이었습니다


정답은 아래 링크에 나와 있죠. ^^

(shard 별로 이루어 집니다.)

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/relevance-intro.html


우선 TF의 경우 뭐 그냥 term frequency 니까 이건 별 문제 없을 거구요.

(기본 per field similarity 입니다.)

IDF의 경우는 그럼 어떻게 할까요 인데요????

IDF는 쉽게말해 index 내 전체 문서에서의 term이 포함된 document frequency 가 되는 건데요.

루씬에서는 뭐 당연히 문제가 안되겠지만 es 에서는 shard 라는 개념이 있죠. 즉 하나의 index를 여러개의 shard 로 나눠서 서로 다른 노드에 가지고 있으니 IDF 를 어떻게 계산 할 수 있을지.... 


제가 보는 관점은 단순 합니다.

- shard 별 document 의 idf 값만 보면 document 의 relevance가 문제일수 있지만, document 의 score 의 경우 tf + idf + field length norm 등 다양한 요소와 함께 계산되기 떄문에 normalized 되었다고 봅니다. 즉 score 값을 신뢰 할 수 있다 입니다.


ㅎㅎ 간만에 검색 질문을 주셔서 재밌었습니다.

: