elasticsearch


Elasticsearch: Parent-child relationship after rollover


Suppose there is a simple blog index which contains two types: blog and comment. One blog can have multiple comments. The index is created like this
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" }
}
}
}
}'
The index %3Cblog-%7Bnow%2Fd%7D-000001%3E is equal to <blog-{now/d}-000001> (see here for more about date math).
We're going to add 'blog-active' alias to this index. This alias is going to be used for storing data.
curl -X POST 'http://localhost:9200/_aliases?pretty=' \
-H 'content-type: application/json' \
-d '{ "actions" : [ { "add" : { "index" : "blog-*", "alias" : "blog-active" } } ] }'
Now if we do the following actions:
1.Add a blog using 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 a comment to the 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.Do a rollover with 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.And add another comment to the blog
curl -X POST \
'http://localhost:9200/blog-active/comment/1?parent=1' \
-H 'content-type: application/json' \
-d '{
"name": "commenter2",
"comment": "new comment2"
}'
Now if we search all blog indices for all comments on 'author1' blogs with (blog-%2A is 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"
}
}
}'
the result only contains first comment.
This is due to the fact that second comment is in the second index which does not have parent blog document in itself. So it doesn't know about the author of the blog.
So, my question is how do I approach parent-child relations when rollover is used?
Is the relationship even possible in that case?
Similar question: ElasticSearch parent/child on different indexes

Related Links

I am looking for ElasticSearch equivalent of below query -
Retrieve docs that contains only allowed tags (exactly equals)
Get max-score of Elasticsearch in CakePHP 3
ElasticSearch multiple terms aggregation order
Copy one column in elasticsearch index into another column applying analyzers
Why is my query ignoring my filter aggregation?
ElasticSearch analyzer that prioritizes order of term appearance in a search
Default elasticsearch configuration for docker container
Add alias to index from template?
Save ElasticSearch snapshot physical files in specific location
Run elasticsearch with docker
elasticsearch: How to reinitialize a node?
Elasticsearch filter on mulitple nested paths
Need to Sort the _term in elastic search aggregation result
Why search_analyzer (keyword) does not work with edgeNgram index_analyer?
Elasticsearch startup: not available immediately

Categories

HOME
yaml
kendo-dropdown
exchange-server
workflow
histogram
cryptography
liferay-7
cypher
material-components
fedora
firebase-database
timber
swarm
locationmanager
getopenfilename
complexity-theory
texas-instruments
orange-api
supervisord
gmp
android-custom-view
acl
channel
ava
fstar
ruby-daemons
points
php-5.3
materialize
fusion
opnet
reporting
seafile-server
knights-tour
quickcheck
android-collapsingtoolbar
bootstrap-sass
stackpanel
cargo
fastlane
iscroll
get-event-store
optionaldataexception
music21
uiautomatorviewer
word-2007
business-rules
dymola
multi-touch
java-2d
msbuild-4.0
static-methods
wicked-pdf
jeditable
outlook.com
android-mapview
opencyc
place
srv-record
canopy
css-paged-media
unhandled
componentart
wicked-gem
whitespace-language
innerhtml
sablecc
incron
google-hangouts
cakephp-2.2
squeezebox
category-theory
two.js
sqlbindparameter
hotswap
property-injection
jomsocial
typesafe-stack
revmob
form-for
indesign-server
eager-loading
email-verification
cgrectmake
arrow
kaazing
jdom
fitch-proofs
nsrangeexception
canonicalization
fragment-identifier
mongrel
comment-conventions

Resources

Encrypt Message