基于索引名称的有条件聚合
我需要在现有项目中添加功能。 到目前为止
return this.client.search({
index,
size: pageSize,
from: currentPage <= 1 ? 0 : (currentPage - 1) * pageSize,
body: {
query: {
query_string: queryObject
}
}
});
代码> index ='机会>',或者我们同时用所有这些,index = ['quotes','机会',...]
现在,我被要求添加此搜索以下内容:
- 如果仅在索引
QUOTES
中完成搜索,则将逻辑添加到仅搜索具有最高版本的引号
字段>字段在所有引号中的值相同master_id
字段值 - quotes index index
如果我们在多个索引中搜索,则仅通过master_id应用此分组,而通过max版本进行过滤到quot > 到目前为止,我已经添加了汇总,其中包含引号的结果,由master_id分组,只有最高
版本
的汇总添加到集合内部的结果:
return this.client.search({
index,
size: pageSize,
from: currentPage <= 1 ? 0 : (currentPage - 1) * pageSize,
body: {
aggs: {
groupByMasterId: {
terms: {
field: 'master_id'
}
},
aggs: {
top_hits: {
size: 1,
sort: [
{
version: 'desc'
}
]
}
}
},
query: {
query_string: queryObject
}
}
});
我需要帮助:
- 是否有一个返回
hits hits
对象而不是聚合
对象的聚合结果的方法?还是我还必须添加单独的逻辑才能提取这些QUOTES
聚合
Elasticsearch响应的对象结果? - 如果在单个查询中搜索了多个索引,我可以将此聚合仅应用于特定索引吗?还是在所有索引的所有结果上完成聚合?
谢谢
I need to add functionality to an existing project.
Until now our fulltext serach only sent index list and query string to elasticsearch(from our js backend):
return this.client.search({
index,
size: pageSize,
from: currentPage <= 1 ? 0 : (currentPage - 1) * pageSize,
body: {
query: {
query_string: queryObject
}
}
});
Until now and still currently we either search by on of the specific indexes, index = 'quotes'
or index = 'opportunities'
, or we serach by all of them at once, index = ['quotes', 'opportunities', ...]
Now, I was asked to add to this search the following:
- If the search is done only in index
quotes
, then add logic to only search for quotes which have highestversion
field value inside a group of all quotes with samemaster_id
field value - If we search in multiple indexes, then only apply this grouping by master_id and filtering by max version to the
quotes
index
What I have so far is I've added aggregation which contains results of quotes, grouped by master_id and only the one with highest version
is added to the result inside aggregation:
return this.client.search({
index,
size: pageSize,
from: currentPage <= 1 ? 0 : (currentPage - 1) * pageSize,
body: {
aggs: {
groupByMasterId: {
terms: {
field: 'master_id'
}
},
aggs: {
top_hits: {
size: 1,
sort: [
{
version: 'desc'
}
]
}
}
},
query: {
query_string: queryObject
}
}
});
I need help with this:
- is there a way to return the result of aggregation inside
hits
object instead ofaggregations
object ? Or do I also have to add separate logic to extract thesequotes
results fromaggregations
object of Elasticsearch response ? - If the multiple indexes are being searched in single query, can I apply this aggregation only to a specific index ? Or are aggregations done on all results from all the indexes ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论