블로그 및 주석의 두 가지 유형이 포함 된 간단한 블로그 색인이 있다고 가정합니다. 하나의 블로그는 여러 개의 댓글을 가질 수 있습니다. 인덱스이탄성 검색 : 롤오버 후 부모 - 자식 관계
curl -X PUT \
'http://localhost:9200/%3Cblog-%7Bnow%2Fd%7D-000001%3E?pretty=' \
-H 'content-type: application/json' \
-d '{
"mappings": {
"comment": {
"_parent": { "type": "blog" },
"properties": {
"name": { "type": "keyword" },
"comment": { "type": "text" }
}
},
"blog": {
"properties": {
"author": { "type": "keyword" },
"subject": { "type": "text" },
"content": { "type": "text" }
}
}
}
}'
인덱스 %3Cblog-%7Bnow%2Fd%7D-000001%3E
처럼 만든 것은 (날짜 수학에 대한 자세한위한 here 참조) <blog-{now/d}-000001>
같다. '블로그 활성'별칭을이 색인에 추가 할 예정입니다. 이 별칭은 데이터를 저장하는 데 사용됩니다.
curl -X POST 'http://localhost:9200/_aliases?pretty=' \
-H 'content-type: application/json' \
-d '{ "actions" : [ { "add" : { "index" : "blog-*", "alias" : "blog-active" } } ] }'
이제 우리는 다음과 같은 작업을 수행하는 경우 :
1.Add blog-active
별칭
curl -X POST http://localhost:9200/blog-active/blog/1 \
-H 'content-type: application/json' \
-d '{
"author": "author1",
"subject": "subject1",
"content": "content1"
}'
2.Add 블로그
curl -X POST \
'http://localhost:9200/blog-active/comment/1?parent=1' \
-H 'content-type: application/json' \
-d '{
"name": "commenter1",
"comment": "new comment1"
}'
3 주석을 사용하여 블로그를 max_docs = 2의 롤오버 사용
우리가 'author1'블로그의 모든 의견에 대한 모든 블로그의 인덱스를 검색하는 경우curl -X POST \
http://localhost:9200/blog-active/_rollover \
-H 'content-type: application/json' \
-d '{
"conditions": {
"max_docs": 2
},
"mappings": {
"comment": {
"_parent": { "type": "blog" },
"properties": {
"name": { "type": "keyword" },
"comment": { "type": "text" }
}
},
"blog": {
"properties": {
"author": { "type": "keyword" },
"subject": { "type": "text" },
"content": { "type": "text" }
}
}
}
}'
4.And (blog-%2A
이 blog-*
입니다)
curl -X POST \
'http://localhost:9200/blog-active/comment/1?parent=1' \
-H 'content-type: application/json' \
-d '{
"name": "commenter2",
"comment": "new comment2"
}'
이제 블로그에
curl -X POST \
http://localhost:9200/blog-%2A/comment/_search \
-H 'content-type: application/json' \
-d '{
"query": {
"has_parent" : {
"query" : {
"match" : { "author" : { "query" : "author1" } }
},
"parent_type" : "blog"
}
}
}'
을 다른 코멘트를 추가 결과에는 첫 번째 주석 만 포함됩니다.
두 번째 메모는 부모 블로그 문서가없는 두 번째 색인에 있기 때문에 발생합니다. 따라서 블로그 작성자에 대해서는 알지 못합니다.
그래서, 내 질문은 롤오버를 사용하는 경우 나 부모 - 자식 관계를 접근 어떻게입니까?
이 경우에도 관계가 가능합니까?
비슷한 질문 : 부모 - 자식 관계의 일부를 구성 ElasticSearch parent/child on different indexes