최초 색인(index)를 생성할 때, shard와 replica의 개수를 설정할 수 있는데, 뜻은..


- shard : 2^32 문서를 저장할 수 있는 저장소 수 (코딩할때 routing을 할 수 있는 hash 컨테이너 수)
      한번 만들어지면 못 바꾸니, 계속 데이터를 사용할 것이라면 shard를 최대값(20)으로 넣는 것이 좋은 것 같다..

- replica : 복제본 수 (HA, 원본 제외한 개수)

       replica가 2이면 총 3개(원본 + 복제본 2개)가 elasticsearch에 저장된다. 최소 1은 설정하는 것이 좋다.


Posted by '김용환'
,


index(색인) 이름 허용 글자는 다음과 같다. 특수 문자가 4개나 지원된다!!


  • 아스키 문자 (a-z), 숫자 (0-9)

  • 점(.), 음수(-), 앤드 (&), 밑줄(_)


Posted by '김용환'
,



참조 

http://www.elastic.co/guide/en/elasticsearch/reference/1.5/search-facets-geo-distance-facet.html



elasticsearch에는 거리를 측정할 수 있는 API가 존재한다. 위 경도를 GeoDistance 클래스를 이용해서 거리를 측정할 수 있다.  SLOPPY_ARC 측정하는 것이 elasticsearch에서는 디폴트로 쓰이고 있다. 

어중간한 라이브러리 보다는 거리 측정 API로는 elasticsearch로 쓰니 좋았다. 


double distance = GeoDistance.SLOPPY_ARC.calculate(srcLatitude, srcLongitude, targetLatitude, targetLongitude, DistanceUnit.METERS);

double distance = GeoDistance.ARC.calculate(srcLatitude, srcLongitude, targetLatitude, targetLongitude, DistanceUnit.METERS);

double distance = GeoDistance.PLANE.calculate(srcLatitude, srcLongitude, targetLatitude, targetLongitude, DistanceUnit.METERS);


arc는 지구(구) 기준으로 정말 실제 거리를 측정한다. 따라서 속도가 이 셋 중에 느리지만, 정확도 높다. 

slooppy_arc는 정확도는 arc에 비해 조금 떨어지지만, 속도가 arc보다 빠르다.

plane은 그냥 지도에서 잰다. 속도가 가장 빠르지만, 실제 거리가 맞지 않는다. 

테스트를 해보니 가까운 거리(1km 이내) 에서는 plane으로 측정하는 의미있을 수 있다. 먼 거리(1km이상)에서는 잘못된 측정이 될 수 있다. arc에서 7km가 나왔는데. plane에서는 11km가 나온다. 


https://github.com/elastic/elasticsearch/blob/master/src/main/java/org/elasticsearch/common/geo/GeoDistance.java



    /**

     * Calculates distance factor.

     */

    FACTOR() {

        @Override

        public double calculate(double sourceLatitude, double sourceLongitude, double targetLatitude, double targetLongitude, DistanceUnit unit) {

            double longitudeDifference = targetLongitude - sourceLongitude;

            double a = Math.toRadians(90D - sourceLatitude);

            double c = Math.toRadians(90D - targetLatitude);

            return (Math.cos(a) * Math.cos(c)) + (Math.sin(a) * Math.sin(c) * Math.cos(Math.toRadians(longitudeDifference)));

        }


        @Override

        public double normalize(double distance, DistanceUnit unit) {

            return Math.cos(distance / unit.getEarthRadius());

        }


        @Override

        public FixedSourceDistance fixedSourceDistance(double sourceLatitude, double sourceLongitude, DistanceUnit unit) {

            return new FactorFixedSourceDistance(sourceLatitude, sourceLongitude, unit);

        }

    },

    /**

     * Calculates distance as points on a globe.

     */

    ARC() {

        @Override

        public double calculate(double sourceLatitude, double sourceLongitude, double targetLatitude, double targetLongitude, DistanceUnit unit) {

            double x1 = sourceLatitude * Math.PI / 180D;

            double x2 = targetLatitude * Math.PI / 180D;

            double h1 = 1D - Math.cos(x1 - x2);

            double h2 = 1D - Math.cos((sourceLongitude - targetLongitude) * Math.PI / 180D);

            double h = (h1 + Math.cos(x1) * Math.cos(x2) * h2) / 2;

            double averageLatitude = (x1 + x2) / 2;

            double diameter = GeoUtils.earthDiameter(averageLatitude);

            return unit.fromMeters(diameter * Math.asin(Math.min(1, Math.sqrt(h))));

        }


        @Override

        public double normalize(double distance, DistanceUnit unit) {

            return distance;

        }


        @Override

        public FixedSourceDistance fixedSourceDistance(double sourceLatitude, double sourceLongitude, DistanceUnit unit) {

            return new ArcFixedSourceDistance(sourceLatitude, sourceLongitude, unit);

        }

    },

    /**

     * Calculates distance as points on a globe in a sloppy way. Close to the pole areas the accuracy

     * of this function decreases.

     */

    SLOPPY_ARC() {


        @Override

        public double normalize(double distance, DistanceUnit unit) {

            return distance;

        }


        @Override

        public double calculate(double sourceLatitude, double sourceLongitude, double targetLatitude, double targetLongitude, DistanceUnit unit) {

            return unit.fromMeters(SloppyMath.haversin(sourceLatitude, sourceLongitude, targetLatitude, targetLongitude) * 1000.0);

        }


        @Override

        public FixedSourceDistance fixedSourceDistance(double sourceLatitude, double sourceLongitude, DistanceUnit unit) {

            return new SloppyArcFixedSourceDistance(sourceLatitude, sourceLongitude, unit);

        }

    };


    /**

     * Default {@link GeoDistance} function. This method should be used, If no specific function has been selected.

     * This is an alias for <code>SLOPPY_ARC</code>

     */

    public static final GeoDistance DEFAULT = SLOPPY_ARC; 



Posted by '김용환'
,



elasticsearch의 geo distance filter의 결과에 대해서 디폴트로 caching하지 않는다. caching하려면 cache값을 true로 지정해야 한다. 


http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-filter.html#_geo_point_type_2


Cachingedit

The result of the filter is not cached by default. The _cache can be set to true to cache the result of the filter. This is handy when the same point and distance parameters are used on several (many) other queries. Note, the process of caching the first execution is higher when caching (since it needs to satisfy different queries).


java API를 쓸 때는 이렇게 쓴다. 


// geo 정보 검색 in 3 km

GeoDistanceFilterBuilder geoDistnaceFilterBuilder =

FilterBuilders.geoDistanceFilter("user_lat_lon")

.distance(3, DistanceUnit.KILOMETERS).lat(37.5133128626990).lon(127.10022875908237).cache(true);


Posted by '김용환'
,



ElasticsearchIntegrationTest를 상속하여 integration test 를 진행할 때,  @Before, @BeforeClass, @After, @AfterClass를 사용할 수 없다. (final), 그러나 @SuiteScopeTest를 사용하면 초기 생성에 대한 메소드를 사용할 수 있다.


setupSuiteScopeCluster() 메소드를 구현하면 before()메소드를 사용하는 것처럼 사용할 수 있다.


아래 예제 코드는 setupSuiteScopeCluster()에서 elasticsearch에 index/type를 생성하고, 데이터 mapping과 데이터를 추가하고, @Test 코드에서 동작할 수 있도록 의미한다. 





import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;

import static org.hamcrest.Matchers.equalTo;


import java.io.IOException;


import org.elasticsearch.action.search.SearchRequestBuilder;

import org.elasticsearch.action.search.SearchResponse;

import org.elasticsearch.cluster.ClusterState;

import org.elasticsearch.cluster.metadata.IndexMetaData;

import org.elasticsearch.cluster.metadata.MappingMetaData;

import org.elasticsearch.common.collect.ImmutableOpenMap;

import org.elasticsearch.common.geo.GeoPoint;

import org.elasticsearch.common.hppc.cursors.ObjectObjectCursor;

import org.elasticsearch.common.unit.DistanceUnit;

import org.elasticsearch.index.query.FilterBuilders;

import org.elasticsearch.index.query.GeoDistanceFilterBuilder;

import org.elasticsearch.index.query.QueryBuilder;

import org.elasticsearch.index.query.QueryBuilders;

import org.elasticsearch.search.SearchHit;

import org.elasticsearch.search.SearchHits;

import org.elasticsearch.test.ElasticsearchIntegrationTest;

import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;

import org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;

import org.elasticsearch.test.ElasticsearchIntegrationTest.SuiteScopeTest;

import org.junit.Ignore;

import org.junit.Test;


@SuiteScopeTest
@ClusterScope(scope = Scope.TEST, numDataNodes = 1)
public class ElasticsearchSetupTest extends ElasticsearchIntegrationTest {

@Override
public void setupSuiteScopeCluster() throws Exception {
// 생성
prepareCreate(
"location_poi")
.setSettings(
"index.number_of_shards", 1)
.setSettings(
"index.number_of_replicas", 0)
      .addMapping(
"location", "user_lat_lon", "type=geo_point", "locId", "type=string,index=not_analyzed" ).execute().actionGet();

// 데이터 입력
GeoPoint[]
geoPoint = {new GeoPoint(37.5133128626991, 127.10022875908236), new GeoPoint(37, 128) };
client().prepareIndex(
"location_poi", "location", "1").setSource(jsonBuilder().startObject()
  .field(
"locId", "da_21160809")
        .array(
"user_lat_lon", geoPoint[0].lon(), geoPoint[0].lat())
        .endObject()
).setRefresh(
true).execute().actionGet();

client().prepareIndex(
"location_poi", "location", "2").setSource(jsonBuilder().startObject()
.field(
"locId", "da_123456")
        .array(
"user_lat_lon", geoPoint[1].lon(), geoPoint[1].lat())
        .endObject()
).setRefresh(
true).execute().actionGet();
refresh();

ensureSearchable(
"location_poi");
}

@Test
public void mapAndGeopointTest() throws IOException {

GeoDistanceFilterBuilder
geoDistnaceFilterBuilder =
FilterBuilders.geoDistanceFilter(
"user_lat_lon")
.distance(3, DistanceUnit.
KILOMETERS).lat(37.5133128626990).lon(127.10022875908237);

QueryBuilder
queryBuilder = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), geoDistnaceFilterBuilder);
SearchRequestBuilder
searchRequest = client().prepareSearch("location_poi").setTypes("location").setQuery(queryBuilder);
SearchResponse
searchResponse = searchRequest.execute().actionGet();

SearchHits
searchHits = searchResponse.getHits();

assertThat(
searchResponse.getHits().getTotalHits(), equalTo(1L));
}
}


Posted by '김용환'
,


elasticsearch 1.4.x 버전 사용시, 아래 elasticsearch 문서대로 clusterscope를 지정하면 컴파일이 되지 않는다. 

numNodes의 필드가 numDataNodes로 바뀌었다. 

(Cluster Scope를 TEST로 하면 빨리 실행된다.)



http://www.elastic.co/guide/en/elasticsearch/reference/1.x/integration-tests.html

@ClusterScope(scope=TEST, numNodes=1)
public class CustomSuggesterSearchTests extends ElasticsearchIntegrationTest {
  // ... tests go here
}


=>>>



@ClusterScope(scope=Scope.TEST, numDataNodes=1)

public class ElasticsearchSimpleTest extends ElasticsearchIntegrationTest {

// ... tests go here

}





Posted by '김용환'
,


java에서 elasticsearch 테스트를 하려면 두가지가 있다.

첫번째, elasticsearch 데몬(standalone)을 실행한 후, index/type 만들고 mapping 구조를 만든 후, 직접 코드에서 요청하는 것

두번째, integration test(local daemon)을 실행할 수 있다.



여기서는 두번째를 얘기하고자 한다. 

elasticsearch의 자바 페이지에서는 integration test를 설명하고 있다. 

아래 문서를 참조로 elasticsearch 1.4.1를 기준으로 작성한다.


http://www.elastic.co/guide/en/elasticsearch/reference/current/testing-framework.html

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



pom.xml 파일은 다음과 같이 구성한다. 



<dependencies>
<properties>
<encoding>UTF-8</encoding>
<jdk.version>1.8</jdk.version>
<spring.groupId>org.springframework</spring.groupId>
<spring.version>3.2.6.RELEASE</spring.version>
<elasticsearch.version>1.4.1</elasticsearch.version>
<lucene.version>4.10.2</lucene.version>
<randomizedtesting-runner.version>2.1.11</randomizedtesting-runner.version>

</properties>

...

<dependencies>

...

<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-test-framework</artifactId>
<version>${lucene.version}</version>
<exclusions>
<exclusion>
<artifactId>randomizedtesting-runner</artifactId>
<groupId>com.carrotsearch.randomizedtesting</groupId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>com.carrotsearch.randomizedtesting</groupId>
<artifactId>randomizedtesting-runner</artifactId>
<version>${randomizedtesting-runner.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>

</dependency>

</dependencies>




코드는 다음과 같이 작성한다. 클러스터로 실행할 수 있다. (클러스터없이는 ElasticsearchTestCase로 할 수 있긴 하나, 대부분의 테스트를 실제 환경과 비슷하게 할 수 있는 ElasticIntegrationTest를 사용하는 것이 나에게는 편한듯하다.)



@ClusterScope(scope = Scope.TEST, numDataNodes = 1)
public class ElasticsearchSimpleTest extends ElasticsearchIntegrationTest {

@Test
public void simpleTest() {
prepareCreate("test").setSettings("index.number_of_shards", 1).execute().actionGet();
client().prepareIndex(
"test", "type1", "1").setSource("field1", "value1", "field2", "value2").setRefresh(true).execute().actionGet();
refresh();

SearchResponse
searchResponse = client().prepareSearch().setQuery("{ \"term\" : { \"field1\" : \"value1\" }}").execute().actionGet();
Assert.assertEquals(1L,
searchResponse.getHits().totalHits());
}

}


(참고로, @ClusterScope를 따로 주지 않으면 여러 노드 4개가 실행된다. ClusterScope를 적절히 활용하는 것이 좋다.)

@ClusterScope(scope = Scope.TEST, numDataNodes = 1)



ElasticsearchIntegrationTest의 상속도는 다음과 같다. 조상은 LuceneTestCast 클래스이다. 

출처: http://thydoc.com/




console(터미널)에서 실행하는 mvn 은 잘 동작한다.

그러나, eclipse test 실행시 에러가 발생한다. 다음과 같이 assertion (-ea가 없다는) 에러가 발생한다.


Assertions mismatch: -ea was not specified but -Dtests.asserts=true
[2015-05-04 11:10:46] [ERROR] [o.e.c.l.l.Log4jESLogger] internalError (139): FAILURE  : com.google.elasticsearch.ElasticsearchSimpleTest
REPRODUCE WITH  : mvn clean test -Dtests.seed=BDAB67EEB7810B0E -Dtests.class=com.google.elasticsearch.ElasticsearchSimpleTest -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([BDAB67EEB7810B0E]: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)



eclipse test에 vm argument에 -ea 를 추가하고 테스트를 실행한다. 




이렇게 실행해도, 랜덤하게 실행이 안될 때가 있다. lucene-core.jar 가 lucene-test-framwork.jar 보다 먼저 선언되면 다음과 같이 Eclipse에서 에러가 발생한다. 

java.lang.AssertionError: fix your classpath to have tests-framework.jar before lucene-core.jar
    __randomizedtesting.SeedInfo.seed([ABFDA059E4FE81D]:0)
    org.apache.lucene.util.TestRuleSetupAndRestoreClassEnv.before(
TestRuleSetupAndRestoreClassEnv.java:178)
    org.apache.lucene.util.AbstractBeforeAfterRule$1.evaluate(
AbstractBeforeAfterRule.java:45)
    org.apache.lucene.util.TestRuleStoreClassName$1.evaluate(
TestRuleStoreClassName.java:42)
    [...com.carrotsearch.randomizedtesting.*]
    org.apache.lucene.util.TestRuleAssertionsRequired$1.evaluate(
TestRuleAssertionsRequired.java:54)
    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)



완성pom.xml은 다음과 같다. lucene-core.jar는 elasticsearch.jar 에서 depencency가 있는 라이브러리라서, lucene-test-framework 뒤에 elasticsearch.jar가 오도록 작성하고 실행하면 잘 동작된다.  




<dependencies>
<properties>
<encoding>UTF-8</encoding>
<jdk.version>1.8</jdk.version>
<spring.groupId>org.springframework</spring.groupId>
<spring.version>3.2.6.RELEASE</spring.version>
<elasticsearch.version>1.4.1</elasticsearch.version>
<lucene.version>4.10.2</lucene.version>
<randomizedtesting-runner.version>2.1.11</randomizedtesting-runner.version>

</properties>

...

<dependencies>

...

<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-test-framework</artifactId>
<version>${lucene.version}</version>
<exclusions>
<exclusion>
<artifactId>randomizedtesting-runner</artifactId>
<groupId>com.carrotsearch.randomizedtesting</groupId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>com.carrotsearch.randomizedtesting</groupId>
<artifactId>randomizedtesting-runner</artifactId>
<version>${randomizedtesting-runner.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>

</dependency>

<dependency>

<groupId>org.elasticsearch</groupId>

<artifactId>elasticsearch</artifactId>

<version>${elasticsearch.version}</version>

</dependency>

</dependencies>







이슈는 parent-pom이 있는 경우이다.  parent-pom에서 elasticsearch를 정의했을 때는 다음과 같이 pom.xml을 정의한다.


parent-pom

..

<elasticsearch.version>1.4.1</elasticsearch.version>

<lucene.version>4.10.2</lucene.version>


..

<dependency>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-test-framework</artifactId>

<version>${lucene.version}</version>

<exclusions>

<exclusion>

<artifactId>randomizedtesting-runner</artifactId>

<groupId>com.carrotsearch.randomizedtesting</groupId>

</exclusion>

</exclusions>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.elasticsearch</groupId>

<artifactId>elasticsearch</artifactId>

<version>${elasticsearch.version}</version>

</dependency>


child-pom

<dependency>

<groupId>org.apache.lucene</groupId>

<artifactId>lucene-test-framework</artifactId>

<version>${lucene.version}</version>

<exclusions>

<exclusion>

<artifactId>randomizedtesting-runner</artifactId>

<groupId>com.carrotsearch.randomizedtesting</groupId>

</exclusion>

</exclusions>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.elasticsearch</groupId>

<artifactId>elasticsearch</artifactId>

<version>${elasticsearch.version}</version>

<scope>test</scope>

<type>test-jar</type>

</dependency>

<dependency>

<groupId>com.carrotsearch.randomizedtesting</groupId>

<artifactId>randomizedtesting-runner</artifactId>

<version>${randomizedtesting-runner.version}</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.hamcrest</groupId>

<artifactId>hamcrest-all</artifactId>

<version>1.3</version>

<scope>test</scope>

</dependency>


이렇세 저장해서 테스트를 진행할 수 있다.


로그는 다음과 같이 정상적으로 출력된다. 


[2015-05-06 11:01:12] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): Test simpleTest(com.google.elasticsearch.ElasticsearchSimpleTest) started

[2015-05-06 11:01:12] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): Setup InternalTestCluster [TEST-Samuelui-MacBook-Pro.local-CHILD_VM=[0]-CLUSTER_SEED=[6220750888563846882]-HASH=[13DB7FA960D9C6F0]] with seed [56548BF9650B2EE2] using [1] data nodes and [0] client nodes

[2015-05-06 11:01:12] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [node_t0] version[1.4.1], pid[38504], build[89d3241/2014-11-26T15:49:29Z]

[2015-05-06 11:01:12] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [node_t0] initializing ...

[2015-05-06 11:01:12] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [node_t0] loaded [], sites []

[2015-05-06 11:01:14] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [node_t0] initialized

[2015-05-06 11:01:14] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [node_t0] starting ...

[2015-05-06 11:01:14] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [node_t0] bound_address {local[1]}, publish_address {local[1]}

[2015-05-06 11:01:14] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [node_t0] TEST-Samuelui-MacBook-Pro.local-CHILD_VM=[0]-CLUSTER_SEED=[6220750888563846882]-HASH=[13DB7FA960D9C6F0]/7RWQIcmMSbCDh12Tu1r8ag

[2015-05-06 11:01:14] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [node_t0] new_master [node_t0][7RWQIcmMSbCDh12Tu1r8ag][Samuelui-MacBook-Pro.local][local[1]]{mode=local}, reason: local-disco-initial_connect(master)

[2015-05-06 11:01:14] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [node_t0] started

[2015-05-06 11:01:14] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): Start Shared Node [node_t0] not shared

[2015-05-06 11:01:14] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [transport_client_node_t0] loaded [], sites []

[2015-05-06 11:01:14] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [node_t0] recovered [0] indices into cluster_state

[2015-05-06 11:01:14] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [transport_client_node_t0] bound_address {local[2]}, publish_address {local[2]}

[2015-05-06 11:01:14] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [ElasticsearchSetupTest#mapAndGeopointTest]: before test

[2015-05-06 11:01:14] [INFO] [o.e.c.l.l.Log4jESLogger] internalInfo (119): [node_t0] [location_poi] creating index, cause [api], shards [1]/[0], mappings [location, _default_]












참조할만한 소스 보기

1. codatlas.com (github 소스 볼 때 tree가 나오지 않음)

http://www.codatlas.com/github.com/elasticsearch/elasticsearch/master/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java

http://www.codatlas.com/github.com/elasticsearch/elasticsearch/master/src/test/java/org/elasticsearch/search/geo/GeoDistanceTests.java





Posted by '김용환'
,


위/경도를 찾는 간단한 방법


1. 구글 지도 접근

https://www.google.co.kr/maps/


2. 구글 지도에서 특정 지역으로 마우스 클릭하면 위/경도가 나타난다.

https://www.google.co.kr/maps/@37.5248389,127.0530228,13z





Posted by '김용환'
,


elasticsearch 실행시 master를 찾는 작업을 진행하고 때로는 실행이 안되는 경우가 있다.

그 이유는 elasticsearch의 기본 설정은 멀티캐스트로 되어 있어, master 를 결정하는 작업을 진행하기 때문이다. 



################################## Discovery ##################################


# Discovery infrastructure ensures nodes can be found within a cluster

# and master node is elected. Multicast discovery is the default.


....


# 1. Disable multicast discovery (enabled by default):

#

#discovery.zen.ping.multicast.enabled: false



그래서, 아래와 같이 discovery.zen.ping.multicast.enabled을 false로 변경한다. master찾는 클러스터링을 하지 않아도 된다. 


discovery.zen.ping.multicast.enabled: false





이상한 로그가 발생하면 위의 부분을 의심하는 것도 좋다. 


[DEBUG][action.index             ] [node_1] observer: timeout notification from cluster service. timeout setting [1m], time since start [1m]


또는 


detecting master failed 

Posted by '김용환'
,




예제

Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch").put("client.transport.sniff", false).build();

TransportClient client = new TransportClient(settings).addTransportAddress(

new InetSocketTransportAddress("es001.in.google.com", 9300));



Settings에 사용할 수 있는 프로퍼티는 다음과 같다.

  • client.transport.diff : 디폴트는 false이다. true로 설정하면 클라이언트는 연결 직후 다른 노드의 주소를 얻어올 수 있다. 
  • client.transport.ignore_cluster_name : 디폴트는 false이다. true로 설정하면 클러스터 이름이 올바른지에 대한 체크(validation)을 하지 않는다. 클라이언트가 지정한 클러스터의 이름과 서버의 클러스터 이름이 다른 경우에 경고가 나온다. 
  • client.transport.ping_timeout : 5s가 디폴트이다.
  • client.transport.nodes_sampler_interval : 디폴트는 5s이다. ping/sample에 대한 주기를 의미한다. 



참조

http://www.elastic.co/guide/en/elasticsearch/client/java-api/current/client.html

Posted by '김용환'
,