'Elastic/TheDefinitiveGuide'에 해당되는 글 33건

  1. 2015.12.15 [Elasticsearch - The Definitive Guide] Phrase Matching
  2. 2015.12.15 [Elasticsearch - The Definitive Guide] Exact Value Fields
  3. 2015.12.10 [Elasticsearch - The Definitive Guide] Relevance is Broken!
  4. 2015.12.10 [Elasticsearch - The Definitive Guide] The match Query
  5. 2015.12.09 [Elasticsearch - The Definitive Guide] Ranges
  6. 2015.12.09 [Elasticsearch - The Definitive Guide] Segment Merging
  7. 2015.12.09 [Elasticsearch - The Definitive Guide] Making Changes Persistent
  8. 2015.12.09 [Elasticsearch - The Definitive Guide] Dynamically Updatable Indices
  9. 2015.12.09 [Elasticsearch - The Definitive Guide] Customizing Dynamic Mapping
  10. 2015.12.03 [Elasticsearch - The Definitive Guide] Index Settings

[Elasticsearch - The Definitive Guide] Phrase Matching

Elastic/TheDefinitiveGuide 2015. 12. 15. 11:20

match query type 중 phrase 에 대한 이해를 돕기 위해 기록 합니다.


원문링크)

https://www.elastic.co/guide/en/elasticsearch/guide/current/phrase-matching.html


원문 Snippet)

What Is a Phraseedit

For a document to be considered a match for the phrase “quick brown fox,” the following must be true:

  • quick, brown, and fox must all appear in the field.
  • The position of brown must be 1 greater than the position of quick.
  • The position of fox must be 2 greater than the position of quick.

If any of these conditions is not met, the document is not considered a match.

Tip

Internally, the match_phrase query uses the low-level span query family to do position-aware matching. Span queries are term-level queries, so they have no analysis phase; they search for the exact term specified.

Thankfully, most people never need to use the span queries directly, as the match_phrasequery is usually good enough. However, certain specialized fields, like patent searches, use these low-level queries to perform very specific, carefully constructed positional searches.

다시 한번 정리 하면,

position-aware matching 을 이용하는 span query

- 첫번째 term 에 대한 position에 의해 나머지 term 들의 matching position 은 quick의 position 보다 커야 합니다.

:

[Elasticsearch - The Definitive Guide] Exact Value Fields

Elastic/TheDefinitiveGuide 2015. 12. 15. 10:57

주의 사항이라 기록해 봅니다.


원문링크)


원문 Snippet)

Avoid using not_analyzed fields in multi_match queries.


:

[Elasticsearch - The Definitive Guide] Relevance is Broken!

Elastic/TheDefinitiveGuide 2015. 12. 10. 12:22

예전에 어느 분이 elasticsearch에서 score 관련 문의를 주셨었는데요.

IDF 값에 대한 global value 를 사용하는지 였습니다.

Elasticsearch에서는 default 설정이 사용하지 않는다 입니다.


서비스와 문서 특징에 따라 다를수는 있지만 저 역시 반드시 global idf 값을 써야 하나 하는 생각이 듭니다.

일단 각설 하고, The Definitive Guide 에 올라온 내용 기록 합니다.


원문링크)

https://www.elastic.co/guide/en/elasticsearch/guide/current/relevance-is-broken.html


원문 Snippet)

However, for performance reasons, Elasticsearch doesn’t calculate the IDF across all documents in the index. Instead, each shard calculates a local IDF for the documents contained in that shard.

...중략...

Don’t use dfs_query_then_fetch in production. It really isn’t required. Just having enough data will ensure that your term frequencies are well distributed. There is no reason to add this extra DFS step to every query that you run.


:

[Elasticsearch - The Definitive Guide] The match Query

Elastic/TheDefinitiveGuide 2015. 12. 10. 11:53

Match Query 와 Term Query 가 어떻게 다른지 간단하게 정리하는 차원에서 기록 합니다.


원문링크)

https://www.elastic.co/guide/en/elasticsearch/guide/current/match-query.html


Match Query Flow)

1. Check the field type

2. Analyze the query string (term query 로 재실행 됩니다.)

3. Find matching docs

4. Score each doc


Term Query Flow)

1. Find matching docs

2. Score each doc


보시면 아시겠지만 match query 보다 term  query가 수행 단계가 적습니다.

결국 match  query 를 실행 하더라도 term query 로 query rewrite 되기 때문에 검색 서비스 개발 시 잘 판단해서 사용하시면 좋을 듯 합니다.


보통은 front end 에서 smart query 또는 query preprocessing 이라고 해서 query stirng 에 대한 1차 가공 후 실제 검색엔진으로 질의시에는 term query  형태로 사용을 많이 합니다.

:

[Elasticsearch - The Definitive Guide] Ranges

Elastic/TheDefinitiveGuide 2015. 12. 9. 17:45

Date type의 field에 대한 range query example 입니다.

기억력 향상을 위해 기록해 봅니다.


원문링크)

https://www.elastic.co/guide/en/elasticsearch/guide/current/_ranges.html


원문 Snippet)

"range" : { "timestamp" : { "gt" : "2014-01-01 00:00:00", "lt" : "2014-01-07 00:00:00" } }


"range" : { "timestamp" : { "gt" : "now-1h" } }


"range" : { "timestamp" : { "gt" : "2014-01-01 00:00:00", "lt" : "2014-01-01 00:00:00||+1M" } }


:

[Elasticsearch - The Definitive Guide] Segment Merging

Elastic/TheDefinitiveGuide 2015. 12. 9. 17:25

알아 두면 매우 좋은 내용입니다.


원문링크)

https://www.elastic.co/guide/en/elasticsearch/guide/current/merge-process.html


원문 Snippet)

With the automatic refresh process creating a new segment every second, it doesn’t take long for the number of segments to explode.

...중략...

This is the moment when those old deleted documents are purged from the filesystem. Deleted documents (or old versions of updated documents) are not copied over to the new bigger segment.

...중략...

The merge process... does not interrupt indexing and searching.

...중략...

Once merging has finished, the old segments are deleted



아래는 merge flow 요약 입니다.


1) merge 하기 위한 new segment 를 생성 합니다. (run optimize)

2) deleted mark 된 것들을 제외 하고 신규 segment 로 merge 대상 segment 들이 합쳐 집니다.)

3) 신규 commit point 를 생성 합니다. (merge 대상 segment 는 제거 하고, 신규 segment 와 아직 merge 가 안된 segment 정보만 기록 합니다.)

4) 검색 가능한 상태가 됩니다.

5) merge 가 완료된 segment는 삭제 됩니다.


※ 이 작업은 상당한 비용이(cpu, disk i/o) 발생 하기 때문에 사용시 주의하셔야 합니다.


:

[Elasticsearch - The Definitive Guide] Making Changes Persistent

Elastic/TheDefinitiveGuide 2015. 12. 9. 17:02

per-segment search works 와 더불어 알아 두면 좋을 것 같아 올려봅니다.


원문링크)

https://www.elastic.co/guide/en/elasticsearch/guide/current/translog.html


원문 Snippet)

Elasticsearch uses this commit point during startup or when reopening an index to decide which segments belong to the current shard.

...중략...

Elasticsearch added a translog, or transaction log, which records every operation in Elasticsearch as it happens.


아래는 원문에 나와 있는 Making Changes Persistent 에 대한 flow 정리 입니다.


1) write in-memory buffer & translog

2) write new segment file without fsync

3) flush in-memory buffer (run refresh and not yet flush)

4) write in-memory buffer & append translog 

5) write new segment file (run flush)

6) flush in-memory buffer

7) write commit point on disk

8) flush filesystem cache with fsync

9) delete old translog

10) create new translog


기본적으로 refresh 와 flush 는 간단하게 아래와 같이 이해 하시면 됩니다.


- refresh

검색 가능한 상태로 만들어 줍니다.


- flush

fsync 작업을 합니다. (commit point 기록 및 translog 제거)

:

[Elasticsearch - The Definitive Guide] Dynamically Updatable Indices

Elastic/TheDefinitiveGuide 2015. 12. 9. 16:25

Elasticsearch가 lucene 기반으로 만들어진 분산검색엔진 이라는 것은 이미 잘 알고 계실겁니다.

하지만 elasticsearch를 사용하시는 분들중 lucene을 잘 아시는 분들은 그렇게 많이 계시지는 않은것 같아 참고 할 만한 좋은 내용이 있어 올려 봅니다.


원문링크)

https://www.elastic.co/guide/en/elasticsearch/guide/current/dynamic-indices.html


원문 Snippet)

[Deletes and Updates]

Segments are immutable, so documents cannot be removed from older segments, nor can older segments be updated to reflect a newer version of a document. Instead, every commit point includes a .del file that lists which documents in which segments have been deleted.

When a document is “deleted,” it is actually just marked as deleted in the .del file. A document that has been marked as deleted can still match a query, but it is removed from the results list before the final query results are returned.

Document updates work in a similar way: when a document is updated, the old version of the document is marked as deleted, and the new version of the document is indexed in a new segment. Perhaps both versions of the document will match a query, but the older deleted version is removed before the query results are returned.


아래는 원문에 나와 있는 per-segment search works 간단 정리 입니다.

1) write in-memory buffer

2) write new segment file from in-memory buffer

3) write commit point (Refresh API on Elasticsearch)

4) flush in-memory buffer

5) searchable


※ 이 내용과 실제 elasticsearch 에서 primary shard 와 replica shard 간 데이터가 sync 되는 것과는 다른 내용입니다.

:

[Elasticsearch - The Definitive Guide] Customizing Dynamic Mapping

Elastic/TheDefinitiveGuide 2015. 12. 9. 15:17

별건 아니고 작은 팁 정도 입니다.


원문링크)

https://www.elastic.co/guide/en/elasticsearch/guide/current/dynamic-mapping.html

https://www.elastic.co/guide/en/elasticsearch/guide/current/custom-dynamic-mapping.html


[date_detection 설정]

PUT /my_index { "mappings": { "my_type": { "date_detection": false } } }


dynamic mapping 의 경우 아래 세 가지 옵션을 가집니다.


true
Add new fields dynamically—the default
false
Ignore new fields
strict
Throw an exception if an unknown field is encountered


date_detection 설정의 경우 문서에도 있지만 처음 들어온 데이터가 date type 으로 인식이 되면 이후 데이터가 string 이더라도 date 로 처리가 된다는 이야기 입니다. 그렇기 때문에 에러가 발생을 하게 될 것이구요.


저는 기본적으로 dynamic mapping 은 false 또는 strict 로 구성 하는 것을 추천 드립니다.

이유는 위와 같은 문제도 있고 하고자 하는 것에 대한 투명성을 보장하는게 좋지 않나 생각해서 입니다.

:

[Elasticsearch - The Definitive Guide] Index Settings

Elastic/TheDefinitiveGuide 2015. 12. 3. 17:24

아주 좋은 글 귀가 보여서 이건 기록을 안할래야.. ^^


원문링크)


원문 Snippet)

Elasticsearch comes with good defaults. Don’t twiddle these knobs until you understand what they do and why you should change them.


Elasticsearch는 잘 모르겠다 싶으시면 그냥 default 로 사용하시는게 제일 좋습니다. :)

: