'indexing'에 해당되는 글 8건

  1. 2021.04.05 [Elasticsearch] Document Indexing 관련
  2. 2018.06.28 [Elasticsearch] HighLevelRestClient 를 이용한 Bulk Indexing 로컬 테스트 결과
  3. 2016.08.10 [Elasticsearch] 2.3.x 에서 색인 성능 올려보기.
  4. 2013.09.17 [Elasticsearch] Bulk Indexing 후 Data Consistency 관리.
  5. 2013.09.11 [Elasticsearch] Indexing performance by kimchy
  6. 2013.04.19 [Elasticsearch] node 별 색인 shard 와 replicas flow.
  7. 2012.12.10 lucene 색인 옵션
  8. 2012.04.27 [solr] Indexing & Searching 맛보기 - solr 기초 마지막..

[Elasticsearch] Document Indexing 관련

Elastic/Elasticsearch 2021. 4. 5. 15:36

Elasticsearch 에서 Indexing 관련해서 봐두면 좋은 Class 입니다.

 

  • InternalEngine
    • Node 레벨에서 선언 되며, Elasticsearch 에서의 대부분의 Operation 에 대한 정의가 되어 있습니다.
  • NodeClient
    • Elasticsearch Cluster 구성 시 Node 에 해당 합니다.
  • IndexShard
    • 물리적인 Index 의 Operation 에 대한 정의가 되어 있습니다.
  • Translog
    • Commit 되지 않은 색인 작업 내역에 대한 Operation 정의가 되어 있습니다.

Flush 에 대한 대략적인 흐름)

    Commit 하면 tranlog 를 indexWriter 가 segments 파일에 write 하고 tranlog 는 flush 되면서 refresh 동기화가 이루어 집니다.
    (Synced flush 의 경우 refresh 가 먼저 수행 됩니다.)

 

:

[Elasticsearch] HighLevelRestClient 를 이용한 Bulk Indexing 로컬 테스트 결과

Elastic/Elasticsearch 2018. 6. 28. 11:35


arirang plug 을 적용해서 돌려본 실행 속도 입니다.


[DEBUG] 2018-07-02 13:12:18.407 [main] MainIndexer - Bulk operation elapsed time [811.0869750976562] sec

[DEBUG] 2018-07-02 13:14:16.595 [main] MainIndexer - Force merge operation elapsed time [118.18800354003906] sec


[Settings]

"settings":{
"number_of_shards":1,
"number_of_replicas":0,
"index.refresh_interval":"1h",
"index.routing.allocation.require.box_type":"indexing",
"index.similarity.default.type":"BM25",
"index":{
"analysis":{
"analyzer":{
"arirang_custom_analyzer":{
"tokenizer":"arirang_tokenizer",
"filter":[
"lowercase",
"trim",
"custom_synonym",
"arirang_filter"
]
}
},
"filter":{
"custom_synonym":{
"type":"synonym_graph",
"synonyms":[]
}
}
}
}
}


[Mappings]

"mappings" : {
"_doc": {
"_source": {
"enabled": true
},
"dynamic_templates": [
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"analyzer": "arirang_custom_analyzer",
"fields": {
"raw": {
"type": "keyword",
"ignore_above": 50
}
}
}
}
}
]
}
}





얼마전 밋업에서 김종민님이 공유해 주신 위키피디아 문서를 가지고 테스트한 결과 입니다.

그냥 제가 만든 Indexer 모듈에 대한 성능 테스트용도로 한번 실험 삼아 돌려 본거라 별 도움이 안될 수 있습니다.


아래 문서는 언제까지 올라가 있을지 모르겠습니다.

빨리 받으시면 될 듯 하내요.


문서 다운로드 링크)

https://s3.ap-northeast-2.amazonaws.com/kr.elastic.co/sample-data/kr-wikipedia-dump.json.tar.gz


위키피디아 문서 색인 테스트 결과)

MacBook Pro

CPU 2.8G i7

MEM 16GB

API : HighLevelRestClient

REST API : _bulk

Settings

primary shard : 1

replica shard : 0

refresh_interval : 1h

similarity : BM25

default analyzer (standard)

Mappings

dynamic mapping

Indexing File Source Size 

3.6GB

Indexing Segment File Size (force merge 전)

11 GB

Indexing Segment File Size (force merge 후)

4.28 GB

Bulk Request Thread Size

5

Bulk Request Document Size (per thread)

500

Bulk Indexing / Force Merge Time

[DEBUG] 2018-06-28 11:06:13.780 [main] MainIndexer - Bulk operation elapsed time [366.6780090332031] sec

[DEBUG] 2018-06-28 11:08:22.254 [main] MainIndexer - Force merge operation elapsed time [128.47300720214844] sec

Indexing Documents

Total indexed document are 1020662


결과적으로 튜닝한 내용은 전혀 없고 그냥 색인기 기능 테스트 정도로 보셔도 될 것 같습니다.


:

[Elasticsearch] 2.3.x 에서 색인 성능 올려보기.

Elastic/Elasticsearch 2016. 8. 10. 16:42

trade-off 가 있긴 하지만 그럼에도 불구하고 색인 성능을 확보 하고 싶으신 분들은 한번 고려해 보셔도 될 것 같습니다.


기본 설정은 sync 입니다.


index.translog.durability: async


추가적으로 software 적인 raid 구조를 사용하고 계시다면, disk i/o 성능이 떨어 지게 되기 때문에 사용하지 않는 걸 추천 드립니다.

:

[Elasticsearch] Bulk Indexing 후 Data Consistency 관리.

Elastic/Elasticsearch 2013. 9. 17. 12:35

벌크 인덱싱 후 간혹 샤드간에 데이터가 왔다 갔다 할 때가 있습니다.

이건 elasticsearch 색인이 잘못 되었다고 보시면 안됩니다.

인덱스와 샤드의 status 정보를 보면

- num_docs

- max_docs

- deleted_docs

이런게 있죠.


기본적으로 벌크 색인 시 empty index 에 색인을 하게 될 텐데요.

색인 도중 문제가 발생해서 일부 색인 데이터가 들어가고 다시 같은 인덱스에 색인을 하게 되면  updateDocument 를 실행 하게 됩니다.

뭐 루씬 API 보시면 이제 add/update 가 하나의 API 로 동작 하긴 합니다.

암튼 이렇게 되다 보니 deleted_docs 가 발생 하게 되고 num_docs 와 max_docs 수치가 안맞게 됩니다.

즉, num_docs = max_docs - deleteed_docs 와 같습니다.


이런 관계로 색인 완료 시 recovery 또는 optimize 작업을 통해서 data consistency 를 보정해 주어야 합니다.

그럼 이걸 어떻게 할까요?


아래 명령어로 해보시고  ES  API 문서 참고 하시면 되겠습니다.

(거의 대부분 default value 입니다.)


[Java API]

new OptimizeRequest()

    .indices(indice)

    .flush(true)

    .onlyExpungeDeletes(false)

    .refresh(true)

    .waitForMerge(true)

    .operationThreading(BroadcastOperationThreading.THREAD_PER_SHARD)

    .maxNumSegments(1)



[Rest API]

curl -XPOST 'http://localhost:9200/indice/_optimize?only_expunge_deletes=false&max_num_segments=1&refresh=true&flush=true&wait_for_merge=true'



[Recovery]

curl -XPOST 'http://localhost:9200/indice/_close'

curl -XPOST 'http://localhost:9200/indice/_open'


client.admin()

    .indices()

    .close(new CloseIndexRequest("indice"));


client.admin()

    .indices()

    .close(new OpenIndexRequest("indice"));



[Reference]

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

http://www.elasticsearch.org/guide/reference/api/admin-indices-open-close/


:

[Elasticsearch] Indexing performance by kimchy

Elastic/Elasticsearch 2013. 9. 11. 17:43

원본 : https://gist.github.com/duydo/2427158



If you want, I can try and help with pointers as to how to improve the indexing speed you get. Its quite easy to really increase it by using some simple guidelines, for example:

- Use create in the index API (assuming you can).
- Relax the real time aspect from 1 second to something a bit higher (index.engine.robin.refresh_interval).
- Increase the indexing buffer size (indices.memory.index_buffer_size), it defaults to the value 10% which is 10% of the heap.
- Increase the number of dirty operations that trigger automatic flush (so the translog won't get really big, even though its FS based) by setting index.translog.flush_threshold (defaults to 5000).
- Increase the memory allocated to elasticsearch node. By default its 1g.
- Start with a lower replica count (even 0), and then once the bulk loading is done, increate it to the value you want it to be using the update_settings API. This will improve things as possibly less shards will be allocated to each machine.
- Increase the number of machines you have so you get less shards allocated per machine.
- Increase the number of shards an index has, so it can make use of more machines.
- Make sure you make full use of the concurrent aspect of elasticsearch. You might not pushing it hard enough. For example, the map reduce job can index things concurrently. Just make sure not to overload elasticsearch.
- Make Lucene use the non compound file format (basically, each segment gets compounded into a single file when using the compound file format). This will increase the number of open files, so make sure you have enough. Set index.merge.policy.use_compound_file to false.

If not using Java, there are more things to play with:

- Try and use the thrift client instead of HTTP.


:

[Elasticsearch] node 별 색인 shard 와 replicas flow.

Elastic/Elasticsearch 2013. 4. 19. 16:27

쉽게 개념을 잡기 위해 Document 색인 요청 시 어떤 flow 로 색인 및 복제를 하는지 간단하게 표현해 봤습니다.


  

 
Find Primary Shard






                                    ↓


 
Perform Index into the Primary Shard






                                    ↓


 
Perform Replica to another Node (using async)



:

lucene 색인 옵션

Elastic/Elasticsearch 2012. 12. 10. 10:50

짧게 정리...

※ Store 옵션
데이터를 저장 할지에 대한 정의.
결국, 검색 후 화면에 출력을 할 것인지 말 것인지에 따라 정의.

Store.YES : 저장 함
Store.NO : 저장 안함 
Store.COMPRESS : 압축 저장 함 (글 내용이 크거나, binary 파일)


※ Index 옵션
검색을 위한 색인을 할지에 대한 정의.
아래는 2.x 대 내용이니 패스, 4.0 을 보면 전부 deprecated 된 걸로 나오내요.
그래도 의미는 파악 하고 있음 좋겠죠.

Index.NO : 색인을 하지 않음 (검색 field 로 사용하지 않음)
Index.TOKENIZED : 검색 가능 하도록 색인 함, analyzer 에 의한 tokenized 수행을 통해 색인을 함.
Index.UN_TOKENIZED : 검색 가능 하도록 색인 함, 단 analyzer 에 의한 분석을 하지 않기 때문에 색인 속도가 빠름. (숫자나 분석이 필요 없는 경우)
Index.NO_NORMS : 검색 가능 하도록 색임 함, 단 색인 속도가 매우 빨라야 할 경우 사용하며, analyzer 에 의한 분석을 수행 하지 않고, field length normalize 를 수행 하지 않음.


http://lucene.apache.org/core/4_0_0/core/index.html

Enum Constant and Description
ANALYZED
Deprecated. 
Index the tokens produced by running the field's value through an Analyzer.
ANALYZED_NO_NORMS
Deprecated. 
Expert: Index the tokens produced by running the field's value through an Analyzer, and also separately disable the storing of norms.
NO
Deprecated. 
Do not index the field value.
NOT_ANALYZED
Deprecated. 
Index the field's value without using an Analyzer, so it can be searched.
NOT_ANALYZED_NO_NORMS
Deprecated. 
Expert: Index the field's value without an Analyzer, and also disable the indexing of norms.

:

[solr] Indexing & Searching 맛보기 - solr 기초 마지막..

Elastic/Elasticsearch 2012. 4. 27. 12:16

가장 중요한 설정 파일 두가지에 대해서 살펴 보았습니다.
solrconfig.xml 과 schema.xml 
아주 중요한 내용들을 설정 하기 때문에 지속적인 학습과 연구가 필요 합니다.
공부합시다.. ㅎㅎ

기본적으로는 아래 문서 보시면 쉽게 이해를 하실 수 있습니다.

우선 post.jar 를 분석해 보겠습니다.
post.jar 를 풀어 보면 SimplePostTool.class 가 들어가 있습니다.

[SimplePostTool.java]
- 이 파일은 package 내 dependency 가 없습니다.
- 그냥 가져다가 사용을 하셔도 됩니다. 
- 저는 solr + tomcat 구성으로 해서 http://localhost:8080/solrdev/update 로 코드 상에 설정 값을 변경했습니다.
- 그럼 색인할 데이터는 어디서 가져와??? 
- 보통은 DB 에 content 를 저장하고 있죠, DB 에 있는 데이터를 select 해 와서 solr 에서 요구하는 format 으로 파일을 생성 하시면 됩니다. xml 을 많이 사용하니 select 해 온 데이터를 xml 파일로 생성 하시면 됩니다.
- 저는 그냥 java project 하나 생성해서 색인할 url 변경하고 SimplePostTool.java 를 다시 묶었습니다.

- 제가 실행시켜 본 화면 입니다.
- 위에 보시면 Main-Class 어쩌구 에러 보이시죠.. 
- MANIFEST 파일을 만들어서 넣어 주시면 됩니다, 중요한건 보이시죠.. 제일 뒤에 개행을 꼭 해주셔야 합니다.

- 그리고 검색을 해보죠.
- 검색 쿼리는 belkin 입니다.

- 참 색인 데이터를 안봤군요.

[ipod_other.xml]
- solr 설치 하시면 example/exampledocs/ 아래 들어 있습니다.

<!--

 Licensed to the Apache Software Foundation (ASF) under one or more

 contributor license agreements.  See the NOTICE file distributed with

 this work for additional information regarding copyright ownership.

 The ASF licenses this file to You under the Apache License, Version 2.0

 (the "License"); you may not use this file except in compliance with

 the License.  You may obtain a copy of the License at


     http://www.apache.org/licenses/LICENSE-2.0


 Unless required by applicable law or agreed to in writing, software

 distributed under the License is distributed on an "AS IS" BASIS,

 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 See the License for the specific language governing permissions and

 limitations under the License.

-->

<add>

<doc>

  <field name="id">F8V7067-APL-KIT</field>

  <field name="name">Belkin Mobile Power Cord for iPod w/ Dock</field>

  <field name="manu">Belkin</field>

  <field name="cat">electronics</field>

  <field name="cat">connector</field>

  <field name="features">car power adapter, white</field>

  <field name="weight">4</field>

  <field name="price">19.95</field>

  <field name="popularity">1</field>

  <field name="inStock">false</field>

  <!-- Buffalo store -->

  <field name="store">45.17614,-93.87341</field>

  <field name="manufacturedate_dt">2005-08-01T16:30:25Z</field>

</doc>

<doc>

  <field name="id">IW-02</field>

  <field name="name">iPod &amp; iPod Mini USB 2.0 Cable</field>

  <field name="manu">Belkin</field>

  <field name="cat">electronics</field>

  <field name="cat">connector</field>

  <field name="features">car power adapter for iPod, white</field>

  <field name="weight">2</field>

  <field name="price">11.50</field>

  <field name="popularity">1</field>

  <field name="inStock">false</field>

  <!-- San Francisco store -->

  <field name="store">37.7752,-122.4232</field>

  <field name="manufacturedate_dt">2006-02-14T23:55:59Z</field>

</doc>

</add>

- 검색 결과 화면 입니다.


자, 지금까지 solr 설치, 설정, 색인과 검색을 맛보기로 해봤습니다.
이제 부터는 각자 열공하셔서 필요한 만큼 사용하시면 될것 같습니다.


Good luck!!

: