'Join'에 해당되는 글 3건

  1. 2016.02.17 [MySQL] SQL JOINS 그림 설명.
  2. 2014.04.16 [Elasticsearch] parent / child 살짝 알아보기. (like join)
  3. 2013.09.24 [Elasticsearch] join 기능 구현은 어떻게?

[MySQL] SQL JOINS 그림 설명.

ITWeb/개발일반 2016. 2. 17. 12:05

RDBMS를 최근 잘 사용 안 했더니 join이 다시 궁금해져서 구글링 했습니다.

이미지로 설명이 잘 나와 있내요. :)





:

[Elasticsearch] parent / child 살짝 알아보기. (like join)

Elastic/Elasticsearch 2014. 4. 16. 16:01

활용편에 소개 할 내용중 하나 인데 오늘 살짝 맛보기만 조금 던져 볼까 합니다.

elasticsearch 를 가지고 like join 같은 기능을 구현 하고 싶으신 분들이 많이 있습니다.

그래서 예전에도 조금 언급은 했었는데요.


elasticsearch 로 비슷하게 구현 가능한 방법은 parent/child 와 nested 구조를 이용하는 것입니다.

오늘은 parent/child 만 알아 볼께요.


우선 레퍼런스 문서는...

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-parent-field.html

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-parent-filter.html

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html


elasticsearch blog 글) 필독!!

http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/


참고 하시기 바랍니다.


1. parent/child 정의 하기.

    "mappings" : {

        "parent_type" : {

             "properties" : {

                "doc_id" : {"type" : "long", "store" : "no", "index" : "not_analyzed", "index_options" : "docs", "ignore_malformed" : true, "include_in_all" : false},

                "content" : {"type" : "string", "store" : "no", "index" : "analyzed", "omit_norms" : false, "index_options" : "offsets", "term_vector" : "with_positions_offsets", "include_in_all" : false}

            }

        },

        "child_type" : {

            "_parent" : {

                "type" : "parent_type"

            },

            "properties" : {

                "keyword" : {"type" : "string", "store" : "no", "index" : "not_analyzed", "omit_norms" : true, "index_options" : "docs", "include_in_all" : false}

            }

        }

    }


위 설정에서 보시는 것 처럼 parent type 과 child type 을 정의 하고 child type 에 parent type 을 지정하면 됩니다.

이 예제는 등록된 글에서 키워드를 추출해서 child 로 저장하는 것입니다.

RDBMS 관점으로 설명을 하자면, 

child_type 이라는 테이블에서 질의를 하고 거기서 나온 결과 값을 가지고 parent_child 테이블에 inner join 하는 구조 입니다.


2. has_child 질의 하기

GET /article/_search

{

    "query": {

        "has_child": {

            "type": "child_type", 

            "query": {

                "term": {

                   "keyword": {

                      "value": "elasticsearch"

                   }

                }

            }

        }

    }

}


위 query 를 보면 child_type 에서 elasticsearch 라는 키워드가 있는 문서를 찾고 그 문서의 parent document 를 return 해 주게 됩니다.


ㅋ 결과를 안보여 드리니까.. 감이 잘 안오신다구요... 

그럼 아래 글 보고 돌려 보시면 되겠습니다. :)

이건 웹상에 잘 정리가 된게 있어서 그냥 링크만 공유 합니다.

http://joelabrahamsson.com/grouping-in-elasticsearch-using-child-documents/


[parent/child 사용시 주의 점]

1. 검색 결과로 child 문서의 field 는 return 되지 않습니다.

2. memory 사용을 많이 합니다.

3. 아직 까지는 nested 보다 느립니다.

4. cross index 지원을 하지 않습니다. (즉, 하나의 index 에 type 으로만 지원 합니다.)

:

[Elasticsearch] join 기능 구현은 어떻게?

Elastic/Elasticsearch 2013. 9. 24. 12:50

아래 링크 참고해서 설계 및 구현 하시면 되겠습니다.

http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/

https://github.com/imotov/elasticsearch-native-script-example

: