'Elastic'에 해당되는 글 498건

  1. 2013.04.09 [elasticsearch] Java API : Get
  2. 2013.04.09 [elasticsearch] es 실행 파일.
  3. 2013.04.08 [elasticsearch] Java API : Index
  4. 2013.04.05 [elasticsearch] Java API : Client
  5. 2013.04.03 [elasticsearch] plugin elasticsearch-hadoop 설치하기.
  6. 2013.04.03 [elasticsearch] tip, 초간단 es start/stop script.
  7. 2013.04.03 [elasticsearch] tip, 0.17.10 on macosx - initialization failed
  8. 2013.02.25 elasticsearch book published!!
  9. 2013.02.18 split brain to elasticsearch.
  10. 2013.02.13 This is about elasticsearch optimization.

[elasticsearch] Java API : Get

Elastic/Elasticsearch 2013. 4. 9. 12:25

본 문서는 개인적인 테스트와 elasticsearch.org 그리고 community 등을 참고해서 작성된 것이며,

정보 교환이 목적입니다.


잘못된 부분에 대해서는 지적 부탁 드립니다.

(예시 코드는 성능 및 보안 검증이 되지 않았습니다.)



[elasticsearch java api 리뷰]

원문 링크 : http://www.elasticsearch.org/guide/reference/java-api/get/


- 이 API는 index 의 id(_id) 를 기반으로 json 형식의 문서를 구할 수 있습니다.


예제는 아래 문서에서 생성한 데이터로 테스트 합니다.

http://jjeong.tistory.com/792


GetResponse response = client.prepareGet("facebook", "post", "2")

        .execute()

        .actionGet();

log.debug("{}", response.getId());

log.debug("{}", response.getSource());


response = client.prepareGet("facebook", "post", "1")

        .setOperationThreaded(false)

        .execute()

        .actionGet();

log.debug("{}", response.getId());

log.debug("{}", response.getSource());

- 보시면 매우 간단 합니다.

- REST URL 방식으로 고치면 http://localhost:9200/facebook/post/2 와 같은 형식을 갖습니다.


좀 더 자사한 내용은 아래 링크 참고 바랍니다.

http://www.elasticsearch.org/guide/reference/api/get/


[.setOperationThreaded 옵션]

- 이 옵션의 기본 값은 true 로 설정이 되어 있습니다.

- operation 에 대한 threading model 을 지원.

- 설명이 어려워서 일단 쉽게 이해를 돕기 위해 소스코드를 좀 봅시다.


[SearchOperationThreading.java]

    /**

     * No threads are used, all the local shards operations will be performed on the calling

     * thread.

     */

    NO_THREADS((byte) 0),

    /**

     * The local shards operations will be performed in serial manner on a single forked thread.

     */

    SINGLE_THREAD((byte) 1),

    /**

     * Each local shard operation will execute on its own thread.

     */

    THREAD_PER_SHARD((byte) 2);


[ThreadingModel.java]

    NONE((byte) 0),

    OPERATION((byte) 1),

    LISTENER((byte) 2),

    OPERATION_LISTENER((byte) 3);


    /**

     * <tt>true</tt> if the actual operation the action represents will be executed

     * on a different thread than the calling thread (assuming it will be executed

     * on the same node).

     */

    public boolean threadedOperation() {

        return this == OPERATION || this == OPERATION_LISTENER;

    }


    /**

     * <tt>true</tt> if the invocation of the action result listener will be executed

     * on a different thread (than the calling thread or an "expensive" thread, like the

     * IO thread).

     */

    public boolean threadedListener() {

        return this == LISTENER || this == OPERATION_LISTENER;

    }


- 주석을 보시면 이해가 되시죠?

- 즉 false이면 자긴껀 자기가 실행 하고, true 이면 thread 를 fork 해서 넘겨준다고 보면 되겠내요.


※ 커뮤니티에 올라와 있는 것들을 보면 아래와 같이 사용하는걸 권장 하는 것 같습니다.

- read operation : setThreadOperation(true) // 즉 선언 하지 않아도 되구요.

- insert/update/delete operation : setThreadOperation(false)


:

[elasticsearch] es 실행 파일.

Elastic/Elasticsearch 2013. 4. 9. 10:37

그냥 궁금해서 본건데.. 


[background]

ElasticSearch.java 가 Bootstrap.java 를 상속 받아서 Bootstrap.main() 실행


[foreground]

실행 시 -f 옵션을 주면 ElasticSearchF.java 에서 System.setProperty("es.foreground", "yes");하고 Bootstrap..main() 실행

:

[elasticsearch] Java API : Index

Elastic/Elasticsearch 2013. 4. 8. 18:42

본 문서는 개인적인 테스트와 elasticsearch.org 그리고 community 등을 참고해서 작성된 것이며,

정보 교환이 목적입니다.


잘못된 부분에 대해서는 지적 부탁 드립니다.

(예시 코드는 성능 및 보안 검증이 되지 않았습니다.)



[elasticsearch java api 리뷰]

원문 링크 : http://www.elasticsearch.org/guide/reference/java-api/index_/


json document 를 생성하는 몇 가지 방법을 설명하고 있습니다.

There are different way of generating JSON document:


- Manually (aka do it yourself) using native byte[] or as a String

- Using Map that will be automatically converted to its JSON equivalent

- Using a third party library to serialize your beans such as Jackson

- Using built-in helpers XContentFactory.jsonBuilder()


위 방법들 중에서 제일 아래 elasticsearch helper 를 이용한 방법을 테스트해 봅니다.


우선 간단하게 index 와 index type 을 정의해 보도록 하겠습니다.

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

    "settings" : { 

        "number_of_shards" : 5,

        "number_of_replicas" : 1  

    },  

    "mappings" : { 

        "post" : { 

            "properties" : { 

                "docid" : { "type" : "string", "store" : "yes", "index" : "not_analyzed" },

                "title" : { "type" : "string", "store" : "yes", "index" : "analyzed", "term_vector" : "yes", "analyzer" : "standard" }

            }   

        }   

    }   

}'


- index 는 facebook 으로 생성을 하고

- index type 은 post 라고 생성을 합니다.

- settings 와 mappings 에 대한 상세한 내용은 아래 링크 참고 하시기 바랍니다.

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

http://www.elasticsearch.org/guide/reference/index-modules/

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

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


index, index type 생성이 끝났으면 이제 색인을 해보도록 하겠습니다

// 생성할 문서가 아래와 같다고 가정

// curl -XPUT 'http://localhost:9200/facebook/post/1' -d '{ "docid" : "henry", "title" : "This is the elasticsearch hadoop test." }'

// curl -XPUT 'http://localhost:9200/facebook/post/2' -d '{ "docid" : "henry", "title" : "elasticsearch test." }'

// curl -XPUT 'http://localhost:9200/facebook/post/3' -d '{ "docid" : "howook", "title" : "hadoop test." }'

// curl -XPUT 'http://localhost:9200/facebook/post/4' -d '{ "docid" : "howook", "title" : "test." }'


    IndexRequestBuilder requestBuilder;

    IndexResponse response;

        

    requestBuilder = client.prepareIndex("facebook", "post");

        

// setSource parameter 로 json string 형태로 등록

    requestBuilder.setId("1");

    requestBuilder.setSource("{ \"docid\" : \"henry\", \"title\" : \"This is the elasticsearch hadoop test.\" }");

    response = requestBuilder.execute().actionGet();


// XContentBuilder 로 setSource 전달

    XContentBuilder jsonBuilderDocument = jsonBuilder().startObject();

        jsonBuilderDocument.field("docid", "henry");

        jsonBuilderDocument.field("title", "elasticsearch test.");

    jsonBuilderDocument.endObject();

        

    requestBuilder.setId("2");

    requestBuilder.setSource(jsonBuilderDocument);

    response = requestBuilder.execute().actionGet();


- IndexRequestBuilder 의 setSource 에 대한 코드를 보시면 어떤 arguments 받는지 알 수 있습니다.

- 그리고 문서 색인에 사용되는 여러가지 다양항 옵션들은 아래 링크를 참고 하시기 바랍니다.

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


아래는 index 생성 시 필요한 settings 와 mappings 에 대한 예제 코드 입니다.

맛보기 참고용 입니다.

IndicesAdminClient indices = client.admin().indices();

CreateIndexRequest indexRequest = new CreateIndexRequest("INDEX_NAME");

    indexRequest

        .settings(jsonBuilderIndexSetting)

        .mapping("INDEX_TYPE_NAME", jsonBuilderIndiceSetting);

indices.create(indexRequest).actionGet();

- INDEX_NAME 은 생성한 index

- INDEX_TYPE_NAME 은 생성한 index type

- jsonBuilerIndexSetting 과 jsonBuilderIndiceSetting 은 XContentBuilder 객체

:

[elasticsearch] Java API : Client

Elastic/Elasticsearch 2013. 4. 5. 19:01

본 문서는 개인적인 테스트와 elasticsearch.org 그리고 community 등을 참고해서 작성된 것이며,

정보 교환이 목적입니다.


잘못된 부분에 대해서는 지적 부탁 드립니다.

(예시 코드는 성능 및 보안 검증이 되지 않았습니다.)



[elasticsearch java api 리뷰]

원문 링크 : http://www.elasticsearch.org/guide/reference/java-api/client/


Java API 를 이용해서 elasticsearch 로 연결하는 두 가지 방법을 설명 하고 있습니다.

1. Node Client

2. Transport Client


※ 커뮤니티에서 관련 글들을 찾다 보면 kimchy 가 추천 하는 방식은 "TransportClient" 를 이용하는 것입니다.


원문에서 보면 elasticsearch 를 사용하면 주의 해야 하는 부분이 나와 있습니다.

사용하시면서 꼭 숙지 하시면 한번 쯤 실수 할 수 있는 오류를 범하지 않을 수 있습니다.

Important:

Please note that you are encouraged to use the same version on client and cluster sides. You may hit some incompatibilities issues when mixing major versions.



※ 요점은 버전을 혼합해서 사용하지 말라는 것입니다. (No Node Available Exception 의 이유가 됩니다.)


원문에 예제 코드가 잘 나와 있기 때문에 제가 테스트 한 코드를 아래 공유 합니다.

ClientConfig clientConfig = ClientConfig.getInstance();


// cluster.name 을 안 줄 경우 NoNodeAvailable 에러 발생.

settings = ImmutableSettings

        .settingsBuilder()

        .put("cluster.name", clientConfig.getProperty("cluster.name"))

        .build();

client = new TransportClient(settings)

        .addTransportAddress(new InetSocketTransportAddress(clientConfig.getProperty("cluster.host1")

                , Integer.parseInt(clientConfig.getProperty("cluster.host1.port"))))

        .addTransportAddress(new InetSocketTransportAddress(clientConfig.getProperty("cluster.host2")

                , Integer.parseInt(clientConfig.getProperty("cluster.host2.port"))));


- ClientConfig : elasticsearch 를 사용하기 위해 필요한 환경설정 값을 구성


elasticsearch client 가 가지는 properties 와 attributes 테스트를 위한 코드

@Test

public void testClientProperties() throws Exception {

    clientManager.openClient();

    Client client = clientManager.getClient();

    AdminClient admin = client.admin();

    ClusterAdminClient cluster = admin.cluster();

    IndicesAdminClient indices = admin.indices();


    ClusterStateRequestBuilder request = cluster.prepareState();

    ClusterStateResponse response = request.execute().actionGet();  

    ClusterState state = response.state();

    AllocationExplanation allocation = state.allocationExplanation();

    ClusterBlocks block = state.blocks();

    MetaData meta = state.metaData();

    RoutingNodes routingNode = state.routingNodes();

    RoutingTable routingTable = state.routingTable();

    ImmutableSettings settings = (ImmutableSettings) meta.persistentSettings();

    

    log.debug("{}", response.clusterName()); // Cluster [test.gruter.es.cluster]

    log.debug("{}", response.getClusterName());

    log.debug("{}", response.getHeaders());

    log.debug("{}", response.getState());

    log.debug("{}", response.state());

    

    log.debug("{}", state.allocationExplanation());

    log.debug("{}", state.blocks());

    log.debug("{}", state.metaData());

    log.debug("{}", state.nodes()); // {[test.gruter.es.cluster2.node][sIj29f-KQziaIbccn_jndg][inet[/127.0.0.1:9301]]{master=true},[test.gruter.es.cluster1.node][kWNDF8SLTxS_axatGmImIg][inet[/127.0.0.1:9300]]{master=true},}

    log.debug("{}", state.routingNodes());

    log.debug("{}", state.routingTable());

    log.debug("{}", state.version());

    

    log.debug("{}", allocation.explanations());

    

    log.debug("{}", block.indices());

    

    log.debug("{}", meta.concreteAllIndices());

    log.debug("{}", meta.concreteAllOpenIndices());

    log.debug("{}", meta.getTotalNumberOfShards());

    log.debug("{}", meta.persistentSettings());

    log.debug("{}", meta.settings());

    

    log.debug("{}", routingNode.getMetaData());

    log.debug("{}", routingNode.getNodesToShards());

    log.debug("{}", routingNode.getRoutingTable());

    log.debug("{}", routingNode.getUnassigned());

    log.debug("{}", routingNode.prettyPrint());

    

    log.debug("{}", routingTable.getIndicesRouting());

    log.debug("{}", routingTable.prettyPrint());

    

    log.debug("{}", settings.getAsMap());

    log.debug("{}", state.nodes().dataNodes());

    log.debug("{}", state.nodes().getSize());

   

    for ( int i=0; i<state.nodes().getSize(); i++ ) {

        log.debug("{}", state.nodes().dataNodes().keySet().toArray()[i]);

    }

    

    Set entries = state.nodes().dataNodes().entrySet();

    Iterator entryIter = entries.iterator();


    while (entryIter.hasNext()) {

        Map.Entry entry = (Map.Entry)entryIter.next();

        Object key = entry.getKey();

        Object value = entry.getValue();

       

        log.debug("key : {}", key);

        log.debug("value : {}", value);

    }

} 

※ 단순히 테스트 및 각 속성들을 보기 위한 코드 입니다.

:

[elasticsearch] plugin elasticsearch-hadoop 설치하기.

Elastic/Elasticsearch 2013. 4. 3. 17:13

Main Site : http://www.elasticsearch.org/guide/reference/modules/gateway/hadoop/

Plugin Site : https://github.com/elasticsearch/elasticsearch-hadoop



bin/plugin -install elasticsearch/elasticsearch-hadoop/1.2.0



:

[elasticsearch] tip, 초간단 es start/stop script.

Elastic/Elasticsearch 2013. 4. 3. 11:37

매번 여러가지 옵션을 주고 실행 시키고, 프로세스 확인해서 죽이고 하기 번거롭죠.

그래서 그냥 간편하게 활용해 보시라고 올려 봅니다.

es 0.17.10 으로 테스트 한거고 아래 스크립트로 0.20.x 나 0.19.x 다 됩니다.


jeong-ui-MacBook-Pro:bin hwjeong$ cat start_es.sh 

#!/bin/bash


ES_PATH=/Users/hwjeong/server/app/es-0.17.10


$ES_PATH/bin/elasticsearch -p $ES_PATH/bin/pidfile.pid -Des.config=$ES_PATH/config/elasticsearch.yml -Xmx256m -Xms256m -Des.max-open-files=true > /dev/null 2>&1 &

jeong-ui-MacBook-Pro:bin hwjeong$ cat stop_es.sh 

#!/bin/bash


ES_PATH=/Users/hwjeong/server/app/es-0.17.10


/bin/kill `cat < $ES_PATH/bin/pidfile.pid `


:

[elasticsearch] tip, 0.17.10 on macosx - initialization failed

Elastic/Elasticsearch 2013. 4. 3. 11:19


적용된 es 가 0.17.10 이라서 mac 에서 압축 풀고 실행했더니 헐.. 바로 오류 던지싶니다.


[2013-04-03 10:56:11,568][INFO ][node                     ] [Halloway, Thomas] {elasticsearch/0.17.10}[638]: initializing ...

[2013-04-03 10:56:11,576][INFO ][plugins                  ] [Halloway, Thomas] loaded [], sites []

[2013-04-03 10:56:14,456][ERROR][bootstrap                ] {elasticsearch/0.17.10}: Initialization Failed ...


kimchy 의 recommendation 은 버전을 올리거나 elasticsearch.in.sh 에서 아래 line 을 수정 하라는 내용입니다.

뭐 이제 이 버전을 사용하고 계신 분들은 없겠지만 그냥 올려 봅니다.


# http://stackoverflow.com/questions/12403489/elasticsearch-os-x-could-not-initialize-class-org-elasticsearch-common-xcontent


this line : JAVA_OPTS="$JAVA_OPTS -Xss128k"

to : JAVA_OPTS="$JAVA_OPTS -Xss256k"


:

elasticsearch book published!!

Elastic/Elasticsearch 2013. 2. 25. 18:21
:

split brain to elasticsearch.

Elastic/Elasticsearch 2013. 2. 18. 18:04

Prevent a split-brain to elasticsearch.


[Recommended Configuration]

[node1]

minimum_master_nodes: 2

discovery.zen.ping.unicast.hosts: [node2, node1]

 

[node2]

minimum_master_nodes: 2

discovery.zen.ping.unicast.hosts: [node1, node2]


split-brain situations?

In case of Clustering

- problem network communications.

- corrupt data of each nodes.


Other references.

http://en.wikipedia.org/wiki/High-availability_cluster

HA clusters usually use a heartbeat private network connection which is used to monitor the health and status of each node in the cluster. One subtle but serious condition all clustering software must be able to handle is split-brain, which occurs when all of the private links go down simultaneously, but the cluster nodes are still running. If that happens, each node in the cluster may mistakenly decide that every other node has gone down and attempt to start services that other nodes are still running. Having duplicate instances of services may cause data corruption on the shared storage.


:

This is about elasticsearch optimization.

Elastic/Elasticsearch 2013. 2. 13. 16:11

Summary is,

- JVM heap size is setup 50% on your system memory.

- index store type is setup by mmapfs. (in case of 64bits solaris)

- adjust index cache config. 

- adjust index merge config.

 

http://blog.bugsense.com/post/35580279634/indexing-bigdata-with-elasticsearch


http://www.slideshare.net/kucrafal/scaling-massive-elastic-search-clusters-rafa-ku-sematext

Page 27.

    index.cache.field.max_size

    index.cache.field.expire

    index.cache.field.type: soft

Page 30.

    JVM Optimization

    -XX:+UseParNewGC

    -XX:+UseConcMarkSweepGC

    -XX:+CMSParallelRemarkEnabled

    

https://gist.github.com/deverton/2970285


JVM Swap 방지

    bootstrap.mlockall: true


http://stackoverflow.com/questions/13757398/elasticsearch-bulk-indexing-gets-slower-over-time-with-constant-number-of-indexe    

    Set the ES_HEAP_SIZE environment variable so that the JVM uses the same value for minimum and maximum memory. Configuring the JVM to have different minimum and maximum values means that each time the JVM needs additional memory (up to the maximum), it will block the Java process to allocate it. Combined with the old Java version, this explains the pauses that our nodes exhibited when introduced to higher load and continuous memory allocation when they were opened up to public searches. The elasticsearch team recommends a setting of 50% of system RAM.    

    

http://www.elasticsearch.org/guide/reference/index-modules/store.html

        using  index.store.type: mmapfs

        

http://jprante.github.com/2012/11/28/Elasticsearch-Java-Virtual-Machine-settings-explained.html  

 

       





: