我只有几天新的ElasticSearch,并且作为一个学习练习实施了一个基本的工作刮刀,汇总了一些工作列表网站的工作,并填充了一些索引,我可以使用一些数据.
我的索引包含列出作业的每个网站的文档.每个文档的属性都是"作业"数组,其中包含该站点上存在的每个作业的对象.我正在考虑将每个作业编入索引作为自己的文档(特别是因为ElasticSearch文档说inner_hits是一个实验性功能)但是现在,我试图看看我是否可以使用ElasticSearch的inner_hits和嵌套功能完成我想做的事情.
我能够查询,过滤和返回仅匹配的作业.但是,我不确定如何将相同的inner_hits约束应用于聚合.
这是我的映射:
{
"jobsitesIdx" : {
"mappings" : {
"sites" : {
"properties" : {
"createdAt" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"jobs" : {
"type" : "nested",
"properties" : {
"company" : {
"type" : "string"
},
"engagement" : {
"type" : "string"
},
"link" : {
"type" : "string",
"index" : "not_analyzed"
},
"location" : {
"type" : "string",
"fields" : {
"raw" : {
"type" : "string",
"index" : "not_analyzed"
}
} …Run Code Online (Sandbox Code Playgroud) ElasticSearch 允许 inner_hits 指定 'from' 和 'size' 参数,就像搜索的外部请求体一样。
例如,假设我的索引包含 25 本书,每本书少于 50 章。以下代码段将返回所有书籍的所有章节,因为 100 本书的“大小”包括所有 25 本书,而 50 章的“大小”包括“少于 50 章”的所有内容:
"index": 'books',
"type": 'book',
"body": {
"from" : 0, "size" : 100, // outer hits, or books
"query": {
"filtered": {
"filter": {
"nested": {
"inner_hits": {
"size": 50 // inner hits, or chapters
},
"path": "chapter",
"query": { "match_all": { } },
}
}
}
},
.
.
.
Run Code Online (Sandbox Code Playgroud)
现在,我想用这样的场景实现分页。我的问题是,如何?
在这种情况下,我是否必须从搜索查询返回上述最大 100 * 50 = 5000 个文档并通过仅显示我感兴趣的切片在应用程序级别实现分页?或者,有没有办法指定在搜索查询本身中返回的总命中数,而与内部/外部大小无关?
我正在查看“响应”如下,因此希望能够对这些数据进行分页: …