首页 > 解决方案 > 弹性低级客户端 - 如何在搜索查询中包含多个索引

问题描述

我正在努力弄清楚如何使用 Elastic 低级客户端在搜索中包含多个索引。

我的理解(对或错)是我应该能够通过逗号分隔来包含多个索引,但这对我不起作用。在下面的代码示例中,我发现指定的第一个索引仍在工作并返回结果,但第二个被忽略了。有任何想法吗?

Appsettings.json 文件:

    // System settings configured here for the WebApp. Applicable to all users.
  "SystemSettings": {
    // Sets the maximum number of distinct values returned by Elastic for a log property
    "_distinctPropertyValuesLimit": 1000, // See LogPropertiesController.cs
    // String for the list of Elastic Search indexes that are searched by default.
    "indexesToSearch": "webapp-razor-*, systemconfig-api-*"
  }

查询类:

_indexesToSearch = configuration.GetSection("SystemSettings").GetSection("indexesToSearch").Value;

var searchResponse = await _elasticLowLevelClient.SearchAsync<StringResponse>(_indexesToSearch, @"
                {
                    ""from"": """ + fromParameter + @""",
                    ""size"": """ + rowsPerPage + @""",
                    ""query"": {
                        ""match"": {
                            """ + searchColumn + @""": {
                                ""query"": """ + searchString + @"""
                            }
                        }
                    },
                    ""sort"": [
                          {
                            ""@timestamp"": {
                            ""order"": ""desc""
                            }
                          }
                       ]
                    }
                ");

在此处输入图像描述

标签: elasticsearch.net-core

解决方案


事实证明,当提供多个值时,索引名称之间不能有任何空格,见下文:

在此处输入图像描述


推荐阅读