是否可以在 elasticsearch 中将 MultiGet 与 Bool 查询结合使用?

Is it possible to combine MultiGet with a Bool query in elasticsearch?

MultiGet api 可用于根据给定的 ID 获取多个文档。 (https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html)

是否可以为此操作添加更多过滤器?给定一个 ID 列表,我只想找到 'color' = 'green'.

的文档

示例:

假设存在以下文档:

目标:

获取 ID 为 1、2 或 4 的文档,其颜色为“绿色”。

预期结果:

[文件 1,文件 4]

到目前为止的查询...:

GET /_mget
{
  "docs": [
    {
      "_index": "my-index-000001",
      "_id": "1"
    },
    {
      "_index": "my-index-000001",
      "_id": "2"
    },
    {
      "_index": "my-index-000001",
      "_id": "4"
    }
  ]
}

或在 C# 中使用 NEST:

var ids = new List<string> {"1", "2", "4"};
var result = await _elasticClient
   .MultiGetAsync(s => s
                    .Index("my-index-000001")
                    .GetMany<SomeRecordObject>(ids)
                );

所以我实际上是在寻找一种将 Bool 查询添加到 MultiGet 查询的方法(我认为)。谁能指出我正确的方向?

multi get 仅用于通过id 获取多个文档。如果您需要执行查询或过滤,则需要搜索查询。

请注意,对于 索引文档,多重获取和搜索具有不同的行为。使用 multi get,可以使用其 id 立即检索 just 索引文档。但是,使用搜索时,只有在刷新索引 (refresh interval elapses (by default, 1 second) or index is manually refreshed with the refresh API) 后,文档才会出现在搜索结果中。