elasticsearch - 在 Elastic 中搜索多个索引时限制每个索引的大小
问题描述
我一直在遵循这篇文章的指导方针。我可以获得所需的输出,但在同一个 DSL 中,如何限制每个索引的结果大小?
POST http://localhost:9200/componenttypeindex%2Cprojecttypeindex/Componenttype%2CProjecttype/_search?pretty=true&typed_keys=true
{
"query": {
"bool": {
"should": [
{
"bool": {
"filter": [
{
"term": {
"_index": {
"value": "componenttypeindex"
}
}
}
],
"must": [
{
"multi_match": {
"fields": [
"Componentname",
"Summary^1.1"
],
"operator": "or",
"query": "test"
}
}
]
}
},
{
"bool": {
"filter": [
{
"term": {
"_index": {
"value": "projecttypeindex"
}
}
}
],
"must": [
{
"multi_match": {
"fields": [
"Projectname",
"Summary^0.3"
],
"operator": "or",
"query": "test"
}
}
]
}
}
]
}
}
}
解决方案
对于给定的查询,您可以使用聚合来分组和限制每个索引的命中数(在本例中,限制为 5):
{
"size": 0,
"query": {
... Same query as above ...
},
"aggs": {
"index_agg": {
"terms": {
"field": "_index",
"size": 20
},
"aggs": {
"hits_per_index": {
"top_hits": {
"size": 5
}
}
}
}
}
}
推荐阅读
- azure - Azure 搜索获取多条记录
- php - 如何在 Magento 2 中使用 Web API 发送 XML 格式的响应?
- python - 如何在 Plotly Python 中编辑 hovertext 标签?
- javascript - 如何使用 v-model 值为 vue-multiselect 选择复选框
- flutter - Flutter,如何解决“RenderBox 未布置:...NEEDS-PAINT”
- angular - 错误:./node_modules/angular-auth-oidc-client/fesm2015/angular-auth-oidc-client.js 4790:36-60 "export 'ɵɵngDeclareInjectable'
- python-3.x - 如何使用python在不同的价格箱中绘制customer_id的计数
- python - 将数据绘制为来自 PosgreSQL 数据库的折线图
- python - 如何在 python 3.8 中正确打印
- javascript - 溢出时平移图像:使用 Javascript 滚动