2017-12-08 4 views
3

저는 현재 Udemy에서 ElasticSearch 과정을 진행하고 있습니다.하지만 비디오에서 ElasticSearch 5에 대해 이야기하고 있으며 현재 ElasticSearch 6을 사용 중입니다. 부모/새 형식의 하위 관계. 비디오에서 ElasticSearch 6에서 부모와 자녀 관계를 만드는 데 문제가 있습니다.

각각 즉 Films ( Star WarsThe Jedi Returns와 을 설정하는 것입니다

지도 교사를 않습니다 다음.

curl -H "Content-Type: application/json" -XPUT "127.0.0.1:9200/series" -d ' 
{ 
    "mappings": { 
     "franchise": {}, 
     "film": { 
      "_parent": { 
       "type": "franchise" 
      } 
     } 
    } 
}' 

를 나는 내가 얻을 매핑을 추가하려고하지만 경우 다음 오류 :

➜ Downloads curl -H "Content-Type: application/json" -XPUT "127.0.0.1:9200/series?pretty" -d ' 
{ 
    "mappings": { 
     "franchise": {}, 
     "film": { 
      "_parent": { 
       "type": "franchise" 
      } 
     } 
    } 
}' 
{ 
    "error" : { 
    "root_cause" : [ 
     { 
     "type" : "illegal_argument_exception", 
     "reason" : "Rejecting mapping update to [series] as the final mapping would have more than 1 type: [franchise, film]" 
     } 
    ], 
    "type" : "illegal_argument_exception", 
    "reason" : "Rejecting mapping update to [series] as the final mapping would have more than 1 type: [franchise, film]" 
    }, 
    "status" : 400 
} 

나는 다음과 같은 리소스를 기반으로 여러 가지를 시도하지만 soluton 찾을 수 없어 : https://www.elastic.co/blog/index-type-parent-child-join-now-future-in-elasticsearch https://www.elastic.co/guide/en/elasticsearch/reference/master/parent-join.html https://github.com/elastic/elasticsearch/issues/20257

TLDR : 누군가가 나를에서 부모 - 자식 관계를 번역에 도움을 주실를 ElasticSearch 6에서 ElastiSearch 5를 올바른 방법으로 사용 하시겠습니까?


다음 단계 (검증) : 매핑이 작동하는지 검증이 볼 때, 교사는 다음 한 다음

그는 얻는 다음 JSON 데이터 :

wget을 http://media.sundog-soft.com/es/series.json

JSON 파일에서

추출 :

{ "create" : { "_index" : "series", "_type" : "franchise", "_id" : "1"} } 
{ "id": "1", "title" : "Star Wars" } 
{ "create" : { "_index" : "series", "_type" : "film", "_id" : "260", "parent" : "1" } } 
{ "id": "260", "title" : "Star Wars: Episode IV - A New Hope", "year":"1977" , "genre":["Action", "Adventure", "Sci-Fi"] } 

와 B

컬 -H "콘텐츠 형식 : 응용 프로그램/JSON"다음을 수행하여 ULK 수입 데이터를 -XPUT "127.0.0.1:9200/_bulk?pretty"--data-진 @의 series.json

+0

대량으로 데이터를 가져 오기 전에 매핑을 사용하여 인덱스를 정의하고 초기화 했습니까? 그렇지 않은 경우 시도해보십시오. –

+0

죄송합니다. 게시물이 약간 잘못 될 수도 있습니다. 매핑을 시도 할 때 문제가 발생합니다. 그게 제가 도움이 필요한 것입니다. 따라서 가로줄이 끊어지기 전까지 교사가하는 일을 설명하고, 아래에 매핑을 시도 할 때 오류가 발생합니다 (나는 일괄 업로드까지받지 못합니다 - 게시물에서 제거 할 것입니다). – 8bithero

답변

5

Elasticsearch 6.0에는 부모/자식 관계를 막는 근본적인 변화가 있습니다.

  1. 하나의 색인은 하나 이상의 유형을 포함 할 수 없습니다. 더 읽기 here.
  2. 부모/자식 관계가 제거되었으므로 _parent 필드도 제거됩니다. 부모/자식의 대신에 가입 필드를 사용해야합니다.

두 개의 고유 한 유형이 있고 두 유형이 동일한 색인에 정의되어야한다는 부모/하위 관계가 필요합니다. 이제는 하나의 인덱스에 여러 유형을 가질 수 없으므로 5.x 및 이전 릴리스에서 지원되는 것과 동일한 방식으로 상위/하위 관계를 지원할 수있는 방법이 없습니다.

부모 필드/자식 관계와 유사한 작업을 수행하는 방법을 보려면 조인 필드 설명서를 참조하십시오. 그러나 이제는 같은 유형의 단일 Elasticsearch 색인 내에 두 가지 종류의 문서를 정의해야합니다.조인 필드 here을 사용하여 "1 대 다수"유형의 관계 (1 질문, 해당 질문과 관련된 여러 답변)를 모델링하는 방법을 설명하는 예제를 참조하십시오.

편집 :

예, 다음과 같이 보일 것 join field의 사용과 Elasticsearch 6.x에서 업데이트.

기존 색인이 있으면 삭제하십시오.

curl -XPUT "http://localhost:9200/series" -H 'Content-Type: application/json' -d' 
{ 
    "mappings": { 
    "doc": { 
     "properties": { 
     "join_field": { 
      "type": "join", 
      "relations": { 
      "franchise": "film" 
      } 
     } 
     } 
    } 
    } 
}' 

귀하의 예제에서 업데이트 된 series.json가 인라인 대량의 요청으로 전송 될 :

curl -XDELETE "http://localhost:9200/series" 

필드에 가입 새로운 인덱스를 생성, 즉 필름 & 프랜차이즈 사이의 관계를 가입 설정 :

curl -XPOST "http://localhost:9200/_bulk" -H 'Content-Type: application/json' -d' 
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "1"} } 
{ "id": "1", "title" : "Star Wars", "join_field": "franchise" } 
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "260", "routing" : "1" } } 
{ "id": "260", "title" : "Star Wars: Episode IV - A New Hope", "year":"1977" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} } 
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "1196", "routing" : "1" } } 
{ "id": "1196", "title" : "Star Wars: Episode V - The Empire Strikes Back", "year":"1980" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} } 
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "1210", "routing" : "1" } } 
{ "id": "1210", "title" : "Star Wars: Episode VI - Return of the Jedi", "year":"1983" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} } 
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "2628", "routing" : "1" } } 
{ "id": "2628", "title" : "Star Wars: Episode I - The Phantom Menace", "year":"1999" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} } 
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "5378", "routing" : "1" } } 
{ "id": "5378", "title" : "Star Wars: Episode II - Attack of the Clones", "year":"2002" , "genre":["Action", "Adventure", "Sci-Fi", "IMAX"], "join_field": {"name": "film", "parent": "1"} } 
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "33493", "routing" : "1" } } 
{ "id": "33493", "title" : "Star Wars: Episode III - Revenge of the Sith", "year":"2005" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} } 
{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "122886", "routing" : "1" } } 
{ "id": "122886", "title" : "Star Wars: Episode VII - The Force Awakens", "year":"2015" , "genre":["Action", "Adventure", "Fantasy", "Sci-Fi", "IMAX"], "join_field": {"name": "film", "parent": "1"} } 
' 

위의 대량 요청 하나의 프랜차이즈와 그 프랜차이즈와 관련된 여러 영화.

프랜차이즈 ID가 1 인 모든 영화를 조회하려면 다음 상위 조회를 사용하십시오. @Pranav Shukla가 주어진 필름이 속한 프랜차이즈를 조회 할 경우 말의 완료에

curl -XGET "http://localhost:9200/series/_search" -H 'Content-Type: application/json' -d' 
{ 
    "query": { 
    "parent_id": { 
     "type": "film", 
     "id": "1" 
    } 
    } 
}' 
+0

답장을 보내 주셔서 감사합니다. 그래, 그 정보를 발견하고 꽤 많은 일을 시도했지만, 궁극적으로 그것을 작동시키지 못했습니다. 누군가가 정확한 구문으로 나를 도울 수 있기를 바랬다./ – 8bithero

+0

문제의 두 유형의 매핑은 무엇입니까? –

+0

미안하지만 말이 안되면. 나는 ElasticSearch에 매우 익숙하다. 그러나 그가 매핑을 위해 한 것은 내가 위에 붙여 넣은 것인데, 나는 다른 모든 것들이 내가 좋아하는 JSON 파일에서 유추 될 수 있다고 생각한다 :'{ "create": { "id": "1", "title": "스타 워즈"}' – 8bithero

0

(예 : "강제 깨어 난다"), 다음 쿼리를 사용할 수 있습니다

curl -XGET localhost:9200/series/_search?pretty -H 'Content-Type: application/json' -d '  
{           
    "query": { 
    "has_child" : { 
     "type": "film", 
     "query": { 
     "match": { 
      "title": "The Force Awakens" 
     } 
     } 
    } 
    } 
}'