我有当前的结构:
localhost:9200/objects/content
{
id:1,
author:{
name:"john"
},
body:"abc"
}
localhost:9200/objects/reaction
{
content_id:1
message:'I like it'
}
如何查询以获取“john”所写内容的所有反应?
这意味着查询 react ,检查 id 指定的内容,如果作者是“某人”。
最佳答案
这个Elasticsearch blog post描述了如何在 Elasticsearch 中管理关系。
您将需要 set a parent mapping在你的 react 和你的内容之间。
{
"reaction" : {
"_parent" : {
"type" : "content"
}
}
}
然后,您会将您的 react 索引为内容 id 1 的子项:
curl -XPOST localhost:9200/test/homes?parent=1 -d'
{
message:'I like it'
}
然后您可以使用 Has Parent Query检索对名为 john 的作者的所有反应:
{
"has_parent" : {
"parent_type" : "content",
"query" : {
"term" : {
"author.name" : "john"
}
}
}
}
关于elasticsearch - 如何查询关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25014747/