elasticsearch - 每个索引的 Elasticsearch 最大文档数
问题描述
我有两个独立的索引 A 和 B,别名为 X。两个索引具有相同的文档结构。当我在别名 X 上使用 size = 20 进行搜索时,我想为索引 B 设置最大文档大小 5。搜索结果应包含索引 B 中的最多 5 个文档。如果索引 B 中没有文档,则搜索结果应包含 20 个文档从索引 A。
是否有任何解决方案可以设置每个索引的最大文档数,以便使用别名跨多个索引进行搜索?
解决方案
您可以使用_msearch
API 来实现。
下面是一个示例查询,说明如何应用它:
POST myalias/_msearch
{"index" : "myindex_news_sports"}
{"query" : {"match_all" : {}}, "from" : 0, "size" : 1}
{"index" : "myindex_news_economics"}
{"query" : {"match_all" : {}}, "from" : 0, "size" : 1}
基本上,_msearch
允许您使用相同的 API 搜索多个请求。有两个不同的查询,您可以在其中指定size
两个不同的索引。
请注意,结果将出现在单独的 JSON 组中(两个结果,每个查询一个)。
示例响应:
{
"took" : 4,
"responses" : [
{ <---- Response for Index 1
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "myindex_news_sports",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"fooNested" : {
"sigma" : 9,
"theta" : 1
}
}
},
{
"_index" : "myindex_news_sports",
"_type" : "_doc",
"_id" : "4",
"_score" : 1.0,
"_source" : {
"fooNested" : {
"sigma" : 9,
"theta" : 1
}
}
}
]
},
"status" : 200
},
{ <---- Response for Index 2
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "myindex_news_economics",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"fooNested" : {
"sigma" : 9,
"theta" : 1
}
}
},
{
"_index" : "myindex_news_economics",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"fooNested" : {
"sigma" : 9,
"theta" : 1
}
}
}
]
},
"status" : 200
}
]
}
不确定这是否适合您,我只是希望这会有所帮助。
推荐阅读
- angular - 离子 4 的多个吐司
- arduino - 继电器 NC NO 引脚是否有不同的容量?
- angular - 对数据库的全局访问不起作用
- ssl - 从多个受信任的 CA 提供商处请求 ssl 证书是否会产生负面影响?
- sql - 如何将子查询结果(具有嵌套连接)与另一个表连接?
- vb.net - 嵌套列表/列表集合
- java - 出现键盘时 ScrollView 不起作用
- javascript - 如何将数据从一个html页面传递到另一个?
- python - 自定义 Spacy NER 模型的总体 F 分数与单个实体 F 分数之间的巨大差异
- python - 有没有办法让这个字符串减少到 3 个单词?