1
elasticsearch入门,不确定这是可能的与一个查询一起分页。我有两种类型的索引:user
& blog
。实施例的映射:elasticsearch搜索结果与子查询
"mappings": {
"user": {
"properties": {
"name" : { "type": "string" }
}
},
"blog": {
"properties": {
"title" : { "type": "string" },
"author_name" : { "type": "string" }
}
}
}
}
样本数据
用户:
[
{"name": "jemmy"},
{"name": "Tom"}
]
博客:
[
{"title": "foo bar", "author": "jemmy"},
{"title": "magic foo", "author": "Tom"},
{"title": "bigdata for dummies", "author": "Tom"},
{"title": "elasticsearch", "author": "Tom"},
{"title": "JS cookbook", "author": "jemmy"},
]
我想上的索引查询这样一种方式,当我搜索对于blog
它应该在每场比赛中进行子查询。例如:
POST /test_index/blog/_search
{
"query": {
"match": {
"_all": "foo"
}
}
}
预期(伪)结果:
[
{
title: "foo bar",
author_name: "Jemmy",
author_post_count: 2
},
{
title: "magic foo",
author_name: "Tom",
author_post_count: 3
}
]
这里author_post_count
是blog
员额数用户已经撰写。如果它可以返回这些博客文章,而不是数量太大。这可能吗?也许这个词我用得不对,但我希望我的问题很明确。
我不认为我理解这个要求。你提到了聚合,但我在你的查询示例中没有看到这样的事情。另外,如果你提供一些文档例子,你想要匹配什么,以及这些例子的结果应该如何,这可能会更好。 –
@AndreiStefan我已经更新了这个问题。也许聚合在这里是一个错误的术语。此外,查询示例是匹配部分。我的问题是如何在结果集中填充'author_post_count' – SamSerious