Angenommen, es gibt einen einfachen Blog-Index, der zwei Typen enthält: Blog und Kommentar. Ein Blog kann mehrere Kommentare enthalten. Der Index wird wie dieser Elasticsearch: Eltern-Kind-Beziehung nach Rollover
erstelltcurl -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" }
}
}
}
}'
Der Index ist %3Cblog-%7Bnow%2Fd%7D-000001%3E
gleich <blog-{now/d}-000001>
(here für mehr über Datum Mathematik sehen). Wir werden diesem Index einen 'blog-aktiven' Alias hinzufügen. Dieser Alias wird zum Speichern von Daten verwendet.
curl -X POST 'http://localhost:9200/_aliases?pretty=' \
-H 'content-type: application/json' \
-d '{ "actions" : [ { "add" : { "index" : "blog-*", "alias" : "blog-active" } } ] }'
Nun, wenn wir tun, um die folgenden Aktionen aus:
1.Add ein Blog mit blog-active
alias
curl -X POST http://localhost:9200/blog-active/blog/1 \
-H 'content-type: application/json' \
-d '{
"author": "author1",
"subject": "subject1",
"content": "content1"
}'
2.Add einen Kommentar zu dem Blog
curl -X POST \
'http://localhost:9200/blog-active/comment/1?parent=1' \
-H 'content-type: application/json' \
-d '{
"name": "commenter1",
"comment": "new comment1"
}'
3 . Führen Sie einen Rollover mit max_docs = 2
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.Und fügen Sie eine weitere Kommentar zum Blog
curl -X POST \
'http://localhost:9200/blog-active/comment/1?parent=1' \
-H 'content-type: application/json' \
-d '{
"name": "commenter2",
"comment": "new comment2"
}'
Wenn wir nun alle Blog-Indizes für alle Kommentare zu 'author1 Blogs mit Suche (blog-%2A
ist blog-*
)
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"
}
}
}'
die Ergebnis enthält nur den ersten Kommentar.
Dies ist aufgrund der Tatsache, dass der zweite Kommentar im zweiten Index ist, die nicht über Eltern-Blog-Dokument in sich hat. So weiß es nicht über den Autor des Blogs.
Also, meine Frage ist, wie gehe ich Eltern-Kind-Beziehungen, wenn Rollover verwendet wird?
Ist die Beziehung in diesem Fall sogar möglich?
ähnliche Frage: ElasticSearch parent/child on different indexes