Elk-Stack版本:8.7.1 Java API 客户端:8.13.1
执行搜索时,我想搜索所有索引,不包括所有以点开头的索引。 根据常规 Elasticsearch Api,您将 *,-.* 放入路径中。
当我使用 Java Api 客户端的 withJson 功能时,我无法使用索引定义路径,我只有索引方法。
那么我怎样才能排除这些索引呢?
Reader queryJson = new StringReader("{\n" +
" \"_source\": {\n" +
" \"excludes\": [ \"@timestamp\", \"@version\" ]\n" +
" },\n" +
" \"size\": 500,\n" +
" \"query\": {\n" +
" \"multi_match\": {\n" +
" \"query\": \"Beratung\",\n" +
" \"fields\": [\"*\"]\n" +
" }\n" +
" }\n" +
"}");
SearchRequest request = SearchRequest.of(b -> b.withJson(queryJson).index("_all"));
SearchResponse<Object> response = esClient.search(request, Object.class);
我尝试将“”、“-.”传递给索引方法,但没有成功。
您尝试的方法
GET *,-.*/_search
是有道理的。如果它不起作用,您可以使用 elasticsearch alias 一次搜索所有索引。将 alias
添加到您想要搜索的所有索引中。
#add alias to some index pattern or all of them one by one
POST _aliases
{
"actions": [
{
"add": {
"index": "test-*",
"alias": "all_indices"
}
}
]
}
#check if it's added
GET _cat/indices/all_indices?v
#search with alias!
GET all_indices/_search