'Nested'에 해당되는 글 5건

  1. 2018.07.03 [Elasticsearch] Nested Query 는 Script Fields 를 지원 하지 않습니다.
  2. 2017.12.13 [Elasticsearch] copy_to mapping 예제
  3. 2014.04.16 [Elasticsearch] parent / child 살짝 알아보기. (like join)
  4. 2013.07.12 [elasticsearch] get score about nested type document.
  5. 2013.04.16 [elasticsearch] Mapping - Array/Object/Nested Type

[Elasticsearch] Nested Query 는 Script Fields 를 지원 하지 않습니다.

Elastic/Elasticsearch 2018. 7. 3. 08:38

안되는 기능입니다.,


{

  "error": {

    "root_cause": [

      {

        "type": "parsing_exception",

        "reason": "[nested] query does not support [script_fields]",

        "line": 22,

        "col": 31

      }

    ],

    "type": "parsing_exception",

    "reason": "[nested] query does not support [script_fields]",

    "line": 22,

    "col": 31

  },

  "status": 400

}


:

[Elasticsearch] copy_to mapping 예제

Elastic/ElasticsearchReferences 2017. 12. 13. 16:31

nested mapping 구조를 가지는 경우 copy_to 에 대한 동작 오류가 몇 건 보고 된게 있어서 코드 보다가 살짝 올려 봅니다.

공식문서는 아래 링크 참고하세요.

https://www.elastic.co/guide/en/elasticsearch/reference/current/copy-to.html


XContentBuilder mapping = jsonBuilder().startObject()
.startObject("type")
.startObject("properties")
.startObject("target")
.field("type", "long")
.field("doc_values", false)
.endObject()
.startObject("n1")
.field("type", "nested")
.startObject("properties")
.startObject("target")
.field("type", "long")
.field("doc_values", false)
.endObject()
.startObject("n2")
.field("type", "nested")
.startObject("properties")
.startObject("target")
.field("type", "long")
.field("doc_values", false)
.endObject()
.startObject("source")
.field("type", "long")
.field("doc_values", false)
.startArray("copy_to")
.value("target") // should go to the root doc
.value("n1.target") // should go to the parent doc
.value("n1.n2.target") // should go to the current doc
.endArray()
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.endObject()
.endObject();


:

[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] get score about nested type document.

Elastic/Elasticsearch 2013. 7. 12. 15:07

Nested type 의 Document Score 는 구할 수 없습니다.

ㅡ.ㅡ;;

그렇다고 이걸 해결 못하면 안되겠지요.

힌트, nested

:

[elasticsearch] Mapping - Array/Object/Nested Type

Elastic/Elasticsearch 2013. 4. 16. 12:04

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

정보 교환이 목적입니다.


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

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



[elasticsearch 리뷰]

원문 링크

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

http://www.elasticsearch.org/guide/reference/mapping/array-type/

http://www.elasticsearch.org/guide/reference/mapping/object-type/

http://www.elasticsearch.org/guide/reference/mapping/nested-type/


원문 예제가 잘 나와 있어 그대로 사용 합니다.


[Document]

"tweet" : { "message" : "some arrays in this tweet...", "tags" : ["elasticsearch", "wow"], "lists" : [ { "name" : "prog_list", "description" : "programming list" }, { "name" : "cool_list", "description" : "cool stuff list" } ] } 


[Mapping]

"tweet" : { "properties" : { "message" : {"type" : "string"}, "tags" : {"type" : "string", "index_name" : "tag"}, "lists" : { "properties" : { "name" : {"type" : "string"}, "description" : {"type" : "string"} } } } } 



[설명]

- elasticsearch 가 지원 하는 장점 중 하나 입니다.

- mapping 정보를 보면 문서 안에 sub 문서를 만들어 넣을 수 있습니다.

- _parent field 의 경우 index type 에 대한 parent 구조를 만들 수 있다고 하면 이건 document 자체에 parent-child 구조를 만들수 있습니다.

- mapping 에서 사용하는 index_name 의 경우 이런 array type 에 대해서 색인 시 field 명을 정의 할 수가 있습니다.

- nested loop 구조를 요구하는 문서가 있을 경우 잘 활용 하시면 좋습니다.

- 예를 들면 대화방이 있고 대화방안에는 여러 사람들이 나눈 대화 목록이있을 경우

"chat_room" : {

    "properties" : {

        "room_id" : {.....},

        ........

        "chat_lists" : {

            "properties" : {

                "chat_id" : {....},

                "sender" : {....},

                "receiver" : {....},

                "message" : {....)

            }

        }

    }

}

    . 이와 같은 구조로 생성을 할 수도 있습니다.



[Object/Nested]

- 이 두가지 type 도 array 와 유사 합니다.

- array 의 경우 [] 이와 같이 사용했다면, object 는 {} 을 사용하게 됩니다.

- nested 타입은 정의한 field 형식의 집합을 구성하게 됩니다. object 로 정의한 형식이 있다면 이것을 여러개의 집합으로 구성을 하게 됩니다.

아래 원문에 나온 예제를 보시면 쉽게 이해가 됩니다.


[Object 예제]

"person" : { "properties" : { "name1" : { "type" : "object", "path" : "just_name", "properties" : { "first1" : {"type" : "string"}, "last1" : {"type" : "string", "index_name" : "i_last_1"} } }, "name2" : { "type" : "object", "path" : "full", "properties" : { "first2" : {"type" : "string"}, "last2" : {"type" : "string", "index_name" : "i_last_2"} } } } } 

- path 는 두가지 옵션을 갖습니다.

    . just_name 과 full

    . just_name 의 경우 mapping 에서 정의한 index_name 을 사용하게 되며

    . full 의 경우 mapping 에서 정의한 full name 을 사용하게 됩니다.

- 즉 원문에 나온 결과를 보시면 이해가 쉽습니다.

JSON NameDocument Field Name
name1/first1first1
name1/last1i_last_1
name2/first2name2.first2
name2/last2name2.i_last_2


[Nested 예제]

{
    "type1" : {
        "properties" : {
            "obj1" : {
                "type" : "nested"
            }
        }
    }
}

- 위 예제에서는 "obj1" 내부 field 정의가 빠져 있으나 설정이 가능 합니다.

- 아래와 같이 하시면 됩니다.


"obj1" : {

    "type" : "nested",

    "properties" : {

        "first_name" : { "type" : "string", ....},

        "last_name" : { "type" : "string", ....}

        ......

    }

}



: