elasticsearch - 如何查询关系

标签 elasticsearch

我有当前的结构:

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/

相关文章:

ElasticSearch:结果窗口太大

python - 在 django 中与 elasticsearch 交互

elasticsearch - Elasticsearch 地理空间搜索实现

elasticsearch - 在Elastic搜索中基于定界符对字符串进行标记

Spring 中的 ElasticSearch 与 @Query

elasticsearch - 如何将Elasticsearch数据复制到新服务器?

elasticsearch - 使用NEST更新ElasticSearch中的子对象

java - 在现有的休息服务中配置 Elastic Search

java - Flume + ElasticSearch 接收器 TTL

elasticsearch - 编写REST API的PUT端点的最佳实践